Skip to content

Commit a07a2e6

Browse files
author
Eugen Freiter
committed
fix thermostat for io13. make temprature unit changeable
1 parent d2b2f4f commit a07a2e6

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/main/java/io/github/hapjava/accessories/TemperatureSensor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,14 @@ default Collection<Service> getServices() {
6060
default TemperatureUnit getTemperatureUnit() {
6161
return TemperatureUnit.CELSIUS;
6262
}
63+
64+
/**
65+
* set default temperature unit of the thermostat. this is the unit thermostat use to display
66+
* temprature. the homekit interface uses celsius.
67+
*
68+
* @param unit the temperature unit of the thermostat.
69+
*/
70+
default void setTemperatureUnit(TemperatureUnit unit) {
71+
// override depending on the thermostat if required.
72+
}
6373
}
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
package io.github.hapjava.impl.characteristics.thermostat;
22

3+
import io.github.hapjava.HomekitCharacteristicChangeCallback;
4+
import io.github.hapjava.accessories.properties.TemperatureUnit;
35
import io.github.hapjava.accessories.thermostat.BasicThermostat;
46
import io.github.hapjava.characteristics.EnumCharacteristic;
7+
import io.github.hapjava.characteristics.EventableCharacteristic;
58
import java.util.concurrent.CompletableFuture;
69

7-
public class TemperatureUnitsCharacteristic extends EnumCharacteristic {
10+
public class TemperatureUnitsCharacteristic extends EnumCharacteristic
11+
implements EventableCharacteristic {
812

913
private final BasicThermostat thermostat;
1014

1115
public TemperatureUnitsCharacteristic(BasicThermostat thermostat) {
12-
super("00000036-0000-1000-8000-0026BB765291", false, true, "The temperature unit", 1);
16+
super("00000036-0000-1000-8000-0026BB765291", true, true, "The temperature unit", 1);
1317
this.thermostat = thermostat;
1418
}
1519

1620
@Override
1721
protected void setValue(Integer value) throws Exception {
18-
// Not writable
22+
thermostat.setTemperatureUnit(
23+
value == 1 ? TemperatureUnit.FAHRENHEIT : TemperatureUnit.CELSIUS);
1924
}
2025

2126
@Override
2227
protected CompletableFuture<Integer> getValue() {
2328
return CompletableFuture.completedFuture(thermostat.getTemperatureUnit().getCode());
2429
}
30+
31+
@Override
32+
public void subscribe(final HomekitCharacteristicChangeCallback callback) {}
33+
34+
@Override
35+
public void unsubscribe() {}
2536
}

0 commit comments

Comments
 (0)