33
33
import org .openhab .core .library .types .StringType ;
34
34
import org .openhab .core .library .unit .ImperialUnits ;
35
35
import org .openhab .core .library .unit .SIUnits ;
36
+ import org .openhab .core .library .unit .Units ;
36
37
import org .openhab .core .types .Command ;
37
38
import org .openhab .core .types .State ;
38
39
43
44
*
44
45
* @author David Graeff - Initial contribution
45
46
* @author Anton Kharuzhy - Implementation
47
+ * @author Vaclav Cejka - added support for humidity and preset_modes
46
48
*/
47
49
@ NonNullByDefault
48
50
public class Climate extends AbstractComponent <Climate .ChannelConfiguration > {
49
51
public static final String ACTION_CH_ID = "action" ;
50
52
public static final String AUX_CH_ID = "aux" ;
51
53
public static final String AWAY_MODE_CH_ID = "away-mode" ;
52
54
public static final String AWAY_MODE_CH_ID_DEPRECATED = "awayMode" ;
55
+ public static final String CURRENT_HUMIDITY_CH_ID = "current-humidity" ;
53
56
public static final String CURRENT_TEMPERATURE_CH_ID = "current-temperature" ;
54
57
public static final String CURRENT_TEMPERATURE_CH_ID_DEPRECATED = "currentTemperature" ;
55
58
public static final String FAN_MODE_CH_ID = "fan-mode" ;
56
59
public static final String FAN_MODE_CH_ID_DEPRECATED = "fanMode" ;
57
60
public static final String HOLD_CH_ID = "hold" ;
58
61
public static final String MODE_CH_ID = "mode" ;
62
+ public static final String PRESET_MODE_CH_ID = "preset-mode" ;
59
63
public static final String SWING_CH_ID = "swing" ;
64
+ public static final String TARGET_HUMIDITY_CH_ID = "target-humidity" ;
60
65
public static final String TEMPERATURE_CH_ID = "temperature" ;
61
66
public static final String TEMPERATURE_HIGH_CH_ID = "temperature-high" ;
62
67
public static final String TEMPERATURE_HIGH_CH_ID_DEPRECATED = "temperatureHigh" ;
@@ -120,6 +125,11 @@ static class ChannelConfiguration extends AbstractChannelConfiguration {
120
125
@ SerializedName ("away_mode_state_topic" )
121
126
protected @ Nullable String awayModeStateTopic ;
122
127
128
+ @ SerializedName ("current_humidity_template" )
129
+ protected @ Nullable String currentHumidityTemplate ;
130
+ @ SerializedName ("current_humidity_topic" )
131
+ protected @ Nullable String currentHumidityTopic ;
132
+
123
133
@ SerializedName ("current_temperature_template" )
124
134
protected @ Nullable String currentTemperatureTemplate ;
125
135
@ SerializedName ("current_temperature_topic" )
@@ -158,6 +168,18 @@ static class ChannelConfiguration extends AbstractChannelConfiguration {
158
168
protected @ Nullable String modeStateTopic ;
159
169
protected List <String > modes = Arrays .asList ("auto" , "off" , "cool" , "heat" , "dry" , "fan_only" );
160
170
171
+ @ SerializedName ("preset_mode_command_template" )
172
+ protected @ Nullable String presetModeCommandTemplate ;
173
+ @ SerializedName ("preset_mode_command_topic" )
174
+ protected @ Nullable String presetModeCommandTopic ;
175
+ @ SerializedName ("preset_mode_state_topic" )
176
+ protected @ Nullable String presetModeStateTopic ;
177
+ @ SerializedName ("preset_mode_value_template" )
178
+ protected @ Nullable String presetModeStateTemplate ;
179
+ @ SerializedName ("preset_modes" )
180
+ protected List <String > presetModes = List .of (); // defaults heavily depend on the
181
+ // type of the device
182
+
161
183
@ SerializedName ("swing_command_template" )
162
184
protected @ Nullable String swingCommandTemplate ;
163
185
@ SerializedName ("swing_command_topic" )
@@ -169,6 +191,15 @@ static class ChannelConfiguration extends AbstractChannelConfiguration {
169
191
@ SerializedName ("swing_modes" )
170
192
protected List <String > swingModes = Arrays .asList ("on" , "off" );
171
193
194
+ @ SerializedName ("target_humidity_command_template" )
195
+ protected @ Nullable String targetHumidityCommandTemplate ;
196
+ @ SerializedName ("target_humidity_command_topic" )
197
+ protected @ Nullable String targetHumidityCommandTopic ;
198
+ @ SerializedName ("target_humidity_state_template" )
199
+ protected @ Nullable String targetHumidityStateTemplate ;
200
+ @ SerializedName ("target_humidity_state_topic" )
201
+ protected @ Nullable String targetHumidityStateTopic ;
202
+
172
203
@ SerializedName ("temperature_command_template" )
173
204
protected @ Nullable String temperatureCommandTemplate ;
174
205
@ SerializedName ("temperature_command_topic" )
@@ -199,6 +230,11 @@ static class ChannelConfiguration extends AbstractChannelConfiguration {
199
230
@ SerializedName ("power_command_topic" )
200
231
protected @ Nullable String powerCommandTopic ;
201
232
233
+ @ SerializedName ("max_humidity" )
234
+ protected BigDecimal maxHumidity = new BigDecimal (99 );
235
+ @ SerializedName ("min_humidity" )
236
+ protected BigDecimal minHumidity = new BigDecimal (30 );
237
+
202
238
protected Integer initial = 21 ;
203
239
@ SerializedName ("max_temp" )
204
240
protected @ Nullable BigDecimal maxTemp ;
@@ -236,6 +272,10 @@ ComponentChannelType.SWITCH, new OnOffValue(), updateListener, null,
236
272
channelConfiguration .awayModeCommandTopic , channelConfiguration .awayModeStateTemplate ,
237
273
channelConfiguration .awayModeStateTopic , commandFilter );
238
274
275
+ buildOptionalChannel (CURRENT_HUMIDITY_CH_ID , ComponentChannelType .NUMBER ,
276
+ new NumberValue (new BigDecimal (0 ), new BigDecimal (100 ), null , Units .PERCENT ), updateListener , null ,
277
+ null , channelConfiguration .currentHumidityTemplate , channelConfiguration .currentHumidityTopic , null );
278
+
239
279
buildOptionalChannel (newStyleChannels ? CURRENT_TEMPERATURE_CH_ID : CURRENT_TEMPERATURE_CH_ID_DEPRECATED ,
240
280
ComponentChannelType .NUMBER ,
241
281
new NumberValue (null , null , precision , channelConfiguration .temperatureUnit .getUnit ()), updateListener ,
@@ -260,11 +300,23 @@ ComponentChannelType.SWITCH, new OnOffValue(), updateListener, null,
260
300
channelConfiguration .modeCommandTemplate , channelConfiguration .modeCommandTopic ,
261
301
channelConfiguration .modeStateTemplate , channelConfiguration .modeStateTopic , commandFilter );
262
302
303
+ buildOptionalChannel (PRESET_MODE_CH_ID , ComponentChannelType .STRING ,
304
+ new TextValue (channelConfiguration .presetModes .toArray (new String [0 ])), updateListener ,
305
+ channelConfiguration .presetModeCommandTemplate , channelConfiguration .presetModeCommandTopic ,
306
+ channelConfiguration .presetModeStateTemplate , channelConfiguration .presetModeStateTopic , commandFilter );
307
+
263
308
buildOptionalChannel (SWING_CH_ID , ComponentChannelType .STRING ,
264
309
new TextValue (channelConfiguration .swingModes .toArray (new String [0 ])), updateListener ,
265
310
channelConfiguration .swingCommandTemplate , channelConfiguration .swingCommandTopic ,
266
311
channelConfiguration .swingStateTemplate , channelConfiguration .swingStateTopic , commandFilter );
267
312
313
+ buildOptionalChannel (TARGET_HUMIDITY_CH_ID , ComponentChannelType .NUMBER ,
314
+ new NumberValue (channelConfiguration .minHumidity , channelConfiguration .maxHumidity , null ,
315
+ Units .PERCENT ),
316
+ updateListener , channelConfiguration .targetHumidityCommandTemplate ,
317
+ channelConfiguration .targetHumidityCommandTopic , channelConfiguration .targetHumidityStateTemplate ,
318
+ channelConfiguration .targetHumidityStateTopic , commandFilter );
319
+
268
320
buildOptionalChannel (TEMPERATURE_CH_ID , ComponentChannelType .NUMBER ,
269
321
new NumberValue (channelConfiguration .minTemp , channelConfiguration .maxTemp ,
270
322
channelConfiguration .tempStep , channelConfiguration .temperatureUnit .getUnit ()),
0 commit comments