17
17
import java .util .List ;
18
18
import java .util .function .Predicate ;
19
19
20
- import javax .measure .Unit ;
21
20
import javax .measure .quantity .Temperature ;
22
21
23
22
import org .eclipse .jdt .annotation .NonNullByDefault ;
32
31
import org .openhab .binding .mqtt .homeassistant .internal .config .dto .AbstractChannelConfiguration ;
33
32
import org .openhab .core .library .types .StringType ;
34
33
import org .openhab .core .library .unit .ImperialUnits ;
35
- import org .openhab .core .library .unit .SIUnits ;
36
34
import org .openhab .core .library .unit .Units ;
37
35
import org .openhab .core .types .Command ;
38
36
import org .openhab .core .types .State ;
@@ -69,29 +67,6 @@ public class Climate extends AbstractComponent<Climate.ChannelConfiguration> {
69
67
public static final String TEMPERATURE_LOW_CH_ID_DEPRECATED = "temperatureLow" ;
70
68
public static final String POWER_CH_ID = "power" ;
71
69
72
- public enum TemperatureUnit {
73
- @ SerializedName ("C" )
74
- CELSIUS (SIUnits .CELSIUS , new BigDecimal ("0.1" )),
75
- @ SerializedName ("F" )
76
- FAHRENHEIT (ImperialUnits .FAHRENHEIT , BigDecimal .ONE );
77
-
78
- private final Unit <Temperature > unit ;
79
- private final BigDecimal defaultPrecision ;
80
-
81
- TemperatureUnit (Unit <Temperature > unit , BigDecimal defaultPrecision ) {
82
- this .unit = unit ;
83
- this .defaultPrecision = defaultPrecision ;
84
- }
85
-
86
- public Unit <Temperature > getUnit () {
87
- return unit ;
88
- }
89
-
90
- public BigDecimal getDefaultPrecision () {
91
- return defaultPrecision ;
92
- }
93
- }
94
-
95
70
private static final String ACTION_OFF = "off" ;
96
71
private static final State ACTION_OFF_STATE = new StringType (ACTION_OFF );
97
72
private static final List <String > ACTION_MODES = List .of (ACTION_OFF , "heating" , "cooling" , "drying" , "idle" , "fan" );
@@ -241,7 +216,7 @@ static class ChannelConfiguration extends AbstractChannelConfiguration {
241
216
@ SerializedName ("min_temp" )
242
217
protected @ Nullable BigDecimal minTemp ;
243
218
@ SerializedName ("temperature_unit" )
244
- protected TemperatureUnit temperatureUnit = TemperatureUnit . CELSIUS ; // System unit by default
219
+ protected @ Nullable TemperatureUnit temperatureUnit ;
245
220
@ SerializedName ("temp_step" )
246
221
protected BigDecimal tempStep = BigDecimal .ONE ;
247
222
protected @ Nullable BigDecimal precision ;
@@ -252,8 +227,16 @@ static class ChannelConfiguration extends AbstractChannelConfiguration {
252
227
public Climate (ComponentFactory .ComponentConfiguration componentConfiguration , boolean newStyleChannels ) {
253
228
super (componentConfiguration , ChannelConfiguration .class , newStyleChannels );
254
229
230
+ TemperatureUnit temperatureUnit = channelConfiguration .temperatureUnit ;
231
+ if (channelConfiguration .temperatureUnit == null ) {
232
+ if (ImperialUnits .FAHRENHEIT .equals (componentConfiguration .getUnitProvider ().getUnit (Temperature .class ))) {
233
+ temperatureUnit = TemperatureUnit .FAHRENHEIT ;
234
+ } else {
235
+ temperatureUnit = TemperatureUnit .CELSIUS ;
236
+ }
237
+ }
255
238
BigDecimal precision = channelConfiguration .precision != null ? channelConfiguration .precision
256
- : channelConfiguration . temperatureUnit .getDefaultPrecision ();
239
+ : temperatureUnit .getDefaultPrecision ();
257
240
final ChannelStateUpdateListener updateListener = componentConfiguration .getUpdateListener ();
258
241
259
242
ComponentChannel actionChannel = buildOptionalChannel (ACTION_CH_ID , ComponentChannelType .STRING ,
@@ -277,9 +260,8 @@ ComponentChannelType.SWITCH, new OnOffValue(), updateListener, null,
277
260
null , channelConfiguration .currentHumidityTemplate , channelConfiguration .currentHumidityTopic , null );
278
261
279
262
buildOptionalChannel (newStyleChannels ? CURRENT_TEMPERATURE_CH_ID : CURRENT_TEMPERATURE_CH_ID_DEPRECATED ,
280
- ComponentChannelType .NUMBER ,
281
- new NumberValue (null , null , precision , channelConfiguration .temperatureUnit .getUnit ()), updateListener ,
282
- null , null , channelConfiguration .currentTemperatureTemplate ,
263
+ ComponentChannelType .TEMPERATURE , new NumberValue (null , null , precision , temperatureUnit .getUnit ()),
264
+ updateListener , null , null , channelConfiguration .currentTemperatureTemplate ,
283
265
channelConfiguration .currentTemperatureTopic , commandFilter );
284
266
285
267
buildOptionalChannel (newStyleChannels ? FAN_MODE_CH_ID : FAN_MODE_CH_ID_DEPRECATED , ComponentChannelType .STRING ,
@@ -317,25 +299,25 @@ ComponentChannelType.SWITCH, new OnOffValue(), updateListener, null,
317
299
channelConfiguration .targetHumidityCommandTopic , channelConfiguration .targetHumidityStateTemplate ,
318
300
channelConfiguration .targetHumidityStateTopic , commandFilter );
319
301
320
- buildOptionalChannel (TEMPERATURE_CH_ID , ComponentChannelType .NUMBER ,
302
+ buildOptionalChannel (TEMPERATURE_CH_ID , ComponentChannelType .TEMPERATURE ,
321
303
new NumberValue (channelConfiguration .minTemp , channelConfiguration .maxTemp ,
322
- channelConfiguration .tempStep , channelConfiguration . temperatureUnit .getUnit ()),
304
+ channelConfiguration .tempStep , temperatureUnit .getUnit ()),
323
305
updateListener , channelConfiguration .temperatureCommandTemplate ,
324
306
channelConfiguration .temperatureCommandTopic , channelConfiguration .temperatureStateTemplate ,
325
307
channelConfiguration .temperatureStateTopic , commandFilter );
326
308
327
309
buildOptionalChannel (newStyleChannels ? TEMPERATURE_HIGH_CH_ID : TEMPERATURE_HIGH_CH_ID_DEPRECATED ,
328
- ComponentChannelType .NUMBER ,
310
+ ComponentChannelType .TEMPERATURE ,
329
311
new NumberValue (channelConfiguration .minTemp , channelConfiguration .maxTemp ,
330
- channelConfiguration .tempStep , channelConfiguration . temperatureUnit .getUnit ()),
312
+ channelConfiguration .tempStep , temperatureUnit .getUnit ()),
331
313
updateListener , channelConfiguration .temperatureHighCommandTemplate ,
332
314
channelConfiguration .temperatureHighCommandTopic , channelConfiguration .temperatureHighStateTemplate ,
333
315
channelConfiguration .temperatureHighStateTopic , commandFilter );
334
316
335
317
buildOptionalChannel (newStyleChannels ? TEMPERATURE_LOW_CH_ID : TEMPERATURE_LOW_CH_ID_DEPRECATED ,
336
- ComponentChannelType .NUMBER ,
318
+ ComponentChannelType .TEMPERATURE ,
337
319
new NumberValue (channelConfiguration .minTemp , channelConfiguration .maxTemp ,
338
- channelConfiguration .tempStep , channelConfiguration . temperatureUnit .getUnit ()),
320
+ channelConfiguration .tempStep , temperatureUnit .getUnit ()),
339
321
updateListener , channelConfiguration .temperatureLowCommandTemplate ,
340
322
channelConfiguration .temperatureLowCommandTopic , channelConfiguration .temperatureLowStateTemplate ,
341
323
channelConfiguration .temperatureLowStateTopic , commandFilter );
0 commit comments