12
12
*/
13
13
package org .openhab .io .homekit .internal .accessories ;
14
14
15
- import java .math .BigDecimal ;
16
15
import java .util .List ;
17
- import java .util .concurrent .CompletableFuture ;
18
16
19
- import org .eclipse .jdt .annotation .Nullable ;
20
17
import org .openhab .io .homekit .internal .HomekitAccessoryUpdater ;
21
18
import org .openhab .io .homekit .internal .HomekitCharacteristicType ;
22
19
import org .openhab .io .homekit .internal .HomekitException ;
23
20
import org .openhab .io .homekit .internal .HomekitSettings ;
24
21
import org .openhab .io .homekit .internal .HomekitTaggedItem ;
25
22
26
- import io .github .hapjava .accessories .TemperatureSensorAccessory ;
27
23
import io .github .hapjava .characteristics .Characteristic ;
28
- import io .github .hapjava .characteristics .HomekitCharacteristicChangeCallback ;
29
24
import io .github .hapjava .characteristics .impl .thermostat .CurrentTemperatureCharacteristic ;
30
- import io .github .hapjava .characteristics .impl .thermostat .TargetTemperatureCharacteristic ;
31
25
import io .github .hapjava .services .impl .TemperatureSensorService ;
32
26
33
27
/**
34
28
* Implements a HomeKit TemperatureSensor using a NumberItem
35
29
*
36
30
* @author Andy Lintner - Initial contribution
37
31
*/
38
- class HomekitTemperatureSensorImpl extends AbstractHomekitAccessoryImpl implements TemperatureSensorAccessory {
32
+ class HomekitTemperatureSensorImpl extends AbstractHomekitAccessoryImpl {
39
33
40
34
public HomekitTemperatureSensorImpl (HomekitTaggedItem taggedItem , List <HomekitTaggedItem > mandatoryCharacteristics ,
41
35
List <Characteristic > mandatoryRawCharacteristics , HomekitAccessoryUpdater updater ,
@@ -46,50 +40,11 @@ public HomekitTemperatureSensorImpl(HomekitTaggedItem taggedItem, List<HomekitTa
46
40
@ Override
47
41
public void init () throws HomekitException {
48
42
super .init ();
49
- addService (new TemperatureSensorService (this ));
50
- }
51
-
52
- @ Override
53
- public CompletableFuture <Double > getCurrentTemperature () {
54
- final @ Nullable Double state = getStateAsTemperature (HomekitCharacteristicType .CURRENT_TEMPERATURE );
55
- return CompletableFuture .completedFuture (state != null ? state : getMinCurrentTemperature ());
56
- }
57
-
58
- @ Override
59
- public void subscribeCurrentTemperature (HomekitCharacteristicChangeCallback callback ) {
60
- subscribe (HomekitCharacteristicType .CURRENT_TEMPERATURE , callback );
61
- }
62
-
63
- @ Override
64
- public double getMinCurrentTemperature () {
65
- // Apple defines default values in Celsius. We need to convert them to Fahrenheit if openHAB is using Fahrenheit
66
- // convertToCelsius and convertFromCelsius are only converting if useFahrenheit is set to true, so no additional
67
- // check here needed
68
- return HomekitCharacteristicFactory .convertToCelsius (
69
- getAccessoryConfiguration (HomekitCharacteristicType .CURRENT_TEMPERATURE , HomekitTaggedItem .MIN_VALUE ,
70
- BigDecimal .valueOf (HomekitCharacteristicFactory
71
- .convertFromCelsius (CurrentTemperatureCharacteristic .DEFAULT_MIN_VALUE )))
72
- .doubleValue ());
73
- }
74
-
75
- @ Override
76
- public double getMaxCurrentTemperature () {
77
- return HomekitCharacteristicFactory .convertToCelsius (
78
- getAccessoryConfiguration (HomekitCharacteristicType .CURRENT_TEMPERATURE , HomekitTaggedItem .MAX_VALUE ,
79
- BigDecimal .valueOf (HomekitCharacteristicFactory
80
- .convertFromCelsius (CurrentTemperatureCharacteristic .DEFAULT_MAX_VALUE )))
81
- .doubleValue ());
82
- }
83
43
84
- @ Override
85
- public double getMinStepCurrentTemperature () {
86
- return HomekitCharacteristicFactory .getTemperatureStep (
87
- getCharacteristic (HomekitCharacteristicType .CURRENT_TEMPERATURE ).get (),
88
- TargetTemperatureCharacteristic .DEFAULT_STEP );
89
- }
44
+ var currentTemperatureCharacteristic = (CurrentTemperatureCharacteristic ) HomekitCharacteristicFactory
45
+ .createCharacteristic (getCharacteristic (HomekitCharacteristicType .CURRENT_TEMPERATURE ).get (),
46
+ getUpdater ());
90
47
91
- @ Override
92
- public void unsubscribeCurrentTemperature () {
93
- unsubscribe (HomekitCharacteristicType .CURRENT_TEMPERATURE );
48
+ addService (new TemperatureSensorService (currentTemperatureCharacteristic ));
94
49
}
95
50
}
0 commit comments