|
1 | 1 | package io.github.hapjava.impl.characteristics.thermostat;
|
2 | 2 |
|
| 3 | +import io.github.hapjava.HomekitCharacteristicChangeCallback; |
| 4 | +import io.github.hapjava.accessories.properties.TemperatureUnit; |
3 | 5 | import io.github.hapjava.accessories.thermostat.BasicThermostat;
|
4 | 6 | import io.github.hapjava.characteristics.EnumCharacteristic;
|
| 7 | +import io.github.hapjava.characteristics.EventableCharacteristic; |
5 | 8 | import java.util.concurrent.CompletableFuture;
|
6 | 9 |
|
7 |
| -public class TemperatureUnitsCharacteristic extends EnumCharacteristic { |
| 10 | +public class TemperatureUnitsCharacteristic extends EnumCharacteristic |
| 11 | + implements EventableCharacteristic { |
8 | 12 |
|
9 | 13 | private final BasicThermostat thermostat;
|
10 | 14 |
|
11 | 15 | 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); |
13 | 17 | this.thermostat = thermostat;
|
14 | 18 | }
|
15 | 19 |
|
16 | 20 | @Override
|
17 | 21 | protected void setValue(Integer value) throws Exception {
|
18 |
| - // Not writable |
| 22 | + thermostat.setTemperatureUnit( |
| 23 | + value == 1 ? TemperatureUnit.FAHRENHEIT : TemperatureUnit.CELSIUS); |
19 | 24 | }
|
20 | 25 |
|
21 | 26 | @Override
|
22 | 27 | protected CompletableFuture<Integer> getValue() {
|
23 | 28 | return CompletableFuture.completedFuture(thermostat.getTemperatureUnit().getCode());
|
24 | 29 | }
|
| 30 | + |
| 31 | + @Override |
| 32 | + public void subscribe(final HomekitCharacteristicChangeCallback callback) { |
| 33 | + thermostat.subscribeTemperatureUnit(callback); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public void unsubscribe() { |
| 38 | + thermostat.unsubscribeTemperatureUnit(); |
| 39 | + } |
25 | 40 | }
|
0 commit comments