Skip to content

Commit 10b5835

Browse files
committed
Added new Temperature and Humidity sensors
1 parent 91ad84e commit 10b5835

File tree

8 files changed

+183
-50
lines changed

8 files changed

+183
-50
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.beowulfe.hap.accessories;
2+
3+
import java.util.Collection;
4+
import java.util.Collections;
5+
import java.util.concurrent.CompletableFuture;
6+
7+
import com.beowulfe.hap.HomekitAccessory;
8+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
9+
import com.beowulfe.hap.Service;
10+
import com.beowulfe.hap.impl.services.HumiditySensorService;
11+
12+
/**
13+
* A humidity sensor that reports the current relative humidity.
14+
*
15+
* @author Andy Lintner
16+
*/
17+
public interface HumiditySensor extends HomekitAccessory {
18+
19+
/**
20+
* Retrieves the current relative humidity.
21+
* @return a future that will contain the humidity as a value between 0 and 100
22+
*/
23+
CompletableFuture<Double> getCurrentRelativeHumidity();
24+
25+
@Override
26+
default public Collection<Service> getServices() {
27+
return Collections.singleton(new HumiditySensorService(this));
28+
}
29+
30+
/**
31+
* Subscribes to changes in the current relative humidity.
32+
* @param callback the function to call when the state changes.
33+
*/
34+
void subscribeCurrentRelativeHumidity(HomekitCharacteristicChangeCallback callback);
35+
36+
/**
37+
* Unsubscribes from changes in the current relative humidity.
38+
*/
39+
void unsubscribeCurrentRelativeHumidity();
40+
41+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.beowulfe.hap.accessories;
2+
3+
import java.util.Collection;
4+
import java.util.Collections;
5+
import java.util.concurrent.CompletableFuture;
6+
7+
import com.beowulfe.hap.HomekitAccessory;
8+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
9+
import com.beowulfe.hap.Service;
10+
import com.beowulfe.hap.accessories.properties.TemperatureUnit;
11+
import com.beowulfe.hap.impl.services.TemperatureSensorService;
12+
13+
/**
14+
* A temperature sensor that reports the current temperature
15+
*
16+
* @author Andy Lintner
17+
*/
18+
public interface TemperatureSensor extends HomekitAccessory {
19+
20+
/**
21+
* Retrieves the current temperature, in celsius degrees.
22+
* @return a future that will contain the temperature.
23+
*/
24+
CompletableFuture<Double> getCurrentTemperature();
25+
26+
@Override
27+
default public Collection<Service> getServices() {
28+
return Collections.singleton(new TemperatureSensorService(this));
29+
}
30+
31+
/**
32+
* Subscribes to changes in the current temperature.
33+
* @param callback the function to call when the state changes.
34+
*/
35+
void subscribeCurrentTemperature(HomekitCharacteristicChangeCallback callback);
36+
37+
/**
38+
* Unsubscribes from changes in the current temperature.
39+
*/
40+
void unsubscribeCurrentTemperature();
41+
42+
/**
43+
* Retrieves the minimum temperature, in celsius degrees, the thermostat can be set to.
44+
* @return the minimum temperature.
45+
*/
46+
double getMinimumTemperature();
47+
48+
/**
49+
* Retrieves the maximum temperature, in celsius degrees, the thermostat can be set to.
50+
* @return the maximum temperature.
51+
*/
52+
double getMaximumTemperature();
53+
54+
/**
55+
* Retrieves the temperature unit of the thermostat. The impact of this is unclear, as the actual temperature
56+
* is always communicated in celsius degrees, and the iOS device uses the user's locale to determine
57+
* the unit to convert to.
58+
* @return the temperature unit of the thermostat.
59+
*/
60+
default TemperatureUnit getTemperatureUnit() { return TemperatureUnit.CELSIUS; }
61+
}

src/main/java/com/beowulfe/hap/accessories/Thermostat.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.beowulfe.hap.HomekitAccessory;
88
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
99
import com.beowulfe.hap.Service;
10-
import com.beowulfe.hap.accessories.properties.TemperatureUnit;
1110
import com.beowulfe.hap.accessories.properties.ThermostatMode;
1211
import com.beowulfe.hap.impl.services.ThermostatService;
1312

@@ -16,7 +15,7 @@
1615
*
1716
* @author Andy Lintner
1817
*/
19-
public interface Thermostat extends HomekitAccessory {
18+
public interface Thermostat extends HomekitAccessory, TemperatureSensor {
2019

2120
/**
2221
* Retrieves the current {@link ThermostatMode} of the thermostat.
@@ -59,43 +58,6 @@ public interface Thermostat extends HomekitAccessory {
5958
*/
6059
void unsubscribeTargetMode();
6160

62-
/**
63-
* Retrieves the temperature unit of the thermostat. The impact of this is unclear, as the actual temperature
64-
* is always communicated in celsius degrees, and the iOS device uses the user's locale to determine
65-
* the unit to convert to.
66-
* @return the temperature unit of the thermostat.
67-
*/
68-
TemperatureUnit getTemperatureUnit();
69-
70-
/**
71-
* Retrieves the minimum temperature, in celsius degrees, the thermostat can be set to.
72-
* @return the minimum temperature.
73-
*/
74-
double getMinimumTemperature();
75-
76-
/**
77-
* Retrieves the maximum temperature, in celsius degrees, the thermostat can be set to.
78-
* @return the maximum temperature.
79-
*/
80-
double getMaximumTemperature();
81-
82-
/**
83-
* Retrieves the current temperature, in celsius degrees.
84-
* @return a future that will contain the temperature.
85-
*/
86-
CompletableFuture<Double> getCurrentTemperature();
87-
88-
/**
89-
* Subscribes to changes in the current temperature.
90-
* @param callback the function to call when the state changes.
91-
*/
92-
void subscribeCurrentTemperature(HomekitCharacteristicChangeCallback callback);
93-
94-
/**
95-
* Unsubscribes from changes in the current temperature.
96-
*/
97-
void unsubscribeCurrentTemperature();
98-
9961
/**
10062
* Retrieves the target temperature, in celsius degrees, used when the thermostat is in {@link ThermostatMode#AUTO} mode.
10163
* @return a future that will contain the target temperature.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.beowulfe.hap.impl.characteristics.humiditysensor;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
5+
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
6+
import com.beowulfe.hap.accessories.HumiditySensor;
7+
import com.beowulfe.hap.characteristics.EventableCharacteristic;
8+
import com.beowulfe.hap.characteristics.FloatCharacteristic;
9+
10+
public class CurrentRelativeHumidityCharacteristic extends FloatCharacteristic implements EventableCharacteristic {
11+
12+
private final HumiditySensor sensor;
13+
14+
public CurrentRelativeHumidityCharacteristic(HumiditySensor sensor) {
15+
super("00000010-0000-1000-8000-0026BB765291", false, true, "Current relative humidity", 0, 100,
16+
0.1, "%");
17+
this.sensor = sensor;
18+
}
19+
20+
@Override
21+
public void subscribe(HomekitCharacteristicChangeCallback callback) {
22+
sensor.subscribeCurrentRelativeHumidity(callback);
23+
}
24+
25+
@Override
26+
public void unsubscribe() {
27+
sensor.unsubscribeCurrentRelativeHumidity();
28+
}
29+
30+
@Override
31+
protected void setValue(Double value) throws Exception {
32+
//Read Only
33+
}
34+
35+
@Override
36+
protected CompletableFuture<Double> getDoubleValue() {
37+
return sensor.getCurrentRelativeHumidity();
38+
}
39+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.beowulfe.hap.impl.characteristics.thermostat;
22

3-
import com.beowulfe.hap.accessories.Thermostat;
3+
import com.beowulfe.hap.accessories.TemperatureSensor;
44
import com.beowulfe.hap.accessories.properties.TemperatureUnit;
55
import com.beowulfe.hap.characteristics.EventableCharacteristic;
66
import com.beowulfe.hap.characteristics.FloatCharacteristic;
77

88
public abstract class AbstractTemperatureCharacteristic extends FloatCharacteristic implements EventableCharacteristic {
99

10-
public AbstractTemperatureCharacteristic(String type, boolean isWritable, String description, Thermostat thermostat) {
11-
super(type, isWritable, true, description, thermostat.getMinimumTemperature(), thermostat.getMaximumTemperature(),
12-
0.1, thermostat.getTemperatureUnit() == TemperatureUnit.CELSIUS ? "celsius" : "fahrenheit");
10+
public AbstractTemperatureCharacteristic(String type, boolean isWritable, String description, TemperatureSensor sensor) {
11+
super(type, isWritable, true, description, sensor.getMinimumTemperature(), sensor.getMaximumTemperature(),
12+
0.1, sensor.getTemperatureUnit() == TemperatureUnit.CELSIUS ? "celsius" : "fahrenheit");
1313
}
1414

1515
}

src/main/java/com/beowulfe/hap/impl/characteristics/thermostat/CurrentTemperatureCharacteristic.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
import java.util.concurrent.CompletableFuture;
44

55
import com.beowulfe.hap.HomekitCharacteristicChangeCallback;
6-
import com.beowulfe.hap.accessories.Thermostat;
6+
import com.beowulfe.hap.accessories.TemperatureSensor;
77

88
public class CurrentTemperatureCharacteristic extends
99
AbstractTemperatureCharacteristic {
1010

11-
private final Thermostat thermostat;
11+
private final TemperatureSensor sensor;
1212

13-
public CurrentTemperatureCharacteristic(Thermostat thermostat) {
13+
public CurrentTemperatureCharacteristic(TemperatureSensor thermostat) {
1414
super("00000011-0000-1000-8000-0026BB765291", false, "Current Temperature", thermostat);
15-
this.thermostat = thermostat;
15+
this.sensor = thermostat;
1616
}
1717

1818
@Override
1919
public void subscribe(HomekitCharacteristicChangeCallback callback) {
20-
thermostat.subscribeCurrentTemperature(callback);
20+
sensor.subscribeCurrentTemperature(callback);
2121
}
2222

2323
@Override
2424
public void unsubscribe() {
25-
thermostat.unsubscribeCurrentTemperature();
25+
sensor.unsubscribeCurrentTemperature();
2626
}
2727

2828
@Override
2929
protected CompletableFuture<Double> getDoubleValue() {
30-
return thermostat.getCurrentTemperature();
30+
return sensor.getCurrentTemperature();
3131
}
3232

3333
@Override
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.beowulfe.hap.impl.services;
2+
3+
import com.beowulfe.hap.accessories.HumiditySensor;
4+
import com.beowulfe.hap.impl.characteristics.common.Name;
5+
import com.beowulfe.hap.impl.characteristics.humiditysensor.CurrentRelativeHumidityCharacteristic;
6+
7+
public class HumiditySensorService extends AbstractServiceImpl {
8+
9+
public HumiditySensorService(HumiditySensor sensor) {
10+
super("00000082-0000-1000-8000-0026BB765291");
11+
addCharacteristic(new Name(sensor));
12+
addCharacteristic(new CurrentRelativeHumidityCharacteristic(sensor));
13+
}
14+
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.beowulfe.hap.impl.services;
2+
3+
import com.beowulfe.hap.accessories.TemperatureSensor;
4+
import com.beowulfe.hap.impl.characteristics.common.Name;
5+
import com.beowulfe.hap.impl.characteristics.thermostat.CurrentTemperatureCharacteristic;
6+
7+
public class TemperatureSensorService extends AbstractServiceImpl {
8+
9+
public TemperatureSensorService(TemperatureSensor sensor) {
10+
super("0000008A-0000-1000-8000-0026BB765291");
11+
addCharacteristic(new Name(sensor));
12+
addCharacteristic(new CurrentTemperatureCharacteristic(sensor));
13+
}
14+
15+
}

0 commit comments

Comments
 (0)