Skip to content

Commit 5299aa4

Browse files
committed
Added support for Thermostat thing with Alert channels.
Signed-off-by: Konstantin Panchenko <kpanchen@konstantech.com>
1 parent 7004c78 commit 5299aa4

15 files changed

+449
-16
lines changed

ESH-INF/thing/channels.xml

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</state>
4545
</channel-type>
4646

47-
<channel-type id="fanMode">
47+
<channel-type id="fanMode">
4848
<item-type>String</item-type>
4949
<label>Fan Mode Status</label>
5050
<description>Current fan mode status</description>
@@ -84,11 +84,65 @@
8484
<state step="0.5" pattern="%.1f %unit%" readOnly="false"/>
8585
</channel-type>
8686

87-
<channel-type id="heatSetPoint">
87+
<channel-type id="heatSetPoint">
8888
<item-type>Number:Temperature</item-type>
8989
<label>Heat Set Point</label>
9090
<description>Gets or sets the heat set point of this zone.</description>
9191
<category>Temperature</category>
9292
<state step="0.5" pattern="%.1f %unit%" readOnly="false"/>
9393
</channel-type>
94+
95+
<channel-type id="alarmDescription">
96+
<item-type>String</item-type>
97+
<label>Alarm Description</label>
98+
<description>Description of alarm being raised.</description>
99+
<category>Text</category>
100+
<state readOnly="true"/>
101+
</channel-type>
102+
103+
<channel-type id="alarmNbr">
104+
<item-type>Number</item-type>
105+
<label>Alarm Code</label>
106+
<description>Code of alarm being raised.</description>
107+
<category>Number</category>
108+
<state readOnly="true"/>
109+
</channel-type>
110+
111+
<channel-type id="alarmType">
112+
<item-type>String</item-type>
113+
<label>Alarm Type</label>
114+
<description>Type of alarm being raised.</description>
115+
<category>Text</category>
116+
<state readOnly="true"/>
117+
</channel-type>
118+
119+
<channel-type id="alarmStatus">
120+
<item-type>String</item-type>
121+
<label>Alarm Status</label>
122+
<description>Status of the alarm.</description>
123+
<category>Text</category>
124+
<state pattern="%s" readOnly="true">
125+
<options>
126+
<option value="ALERT_CLEARED">Alert has been cleared</option>
127+
<option value="ALERT_RAISED">Alert is active</option>
128+
</options>
129+
</state>
130+
</channel-type>
131+
132+
<channel-type id="dateTimeSet">
133+
<item-type>DateTime</item-type>
134+
<label>Alarm Date Set</label>
135+
<description>Date and Time when alarm was raised.</description>
136+
<category>DateTime</category>
137+
<state readOnly="true"/>
138+
</channel-type>
139+
140+
<channel-type id="alertNumber">
141+
<item-type>Number</item-type>
142+
<label>Alert Number</label>
143+
<description>Display alert with specified number (up to 20).</description>
144+
<category>Alert Number</category>
145+
<state readOnly="false" min="0" max="20"/>
146+
</channel-type>
147+
94148
</thing:thing-descriptions>

ESH-INF/thing/thing-types.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
</supported-bridge-type-refs>
1010
<label>iComfort WiFi Thermostat</label>
1111
<description>This represents the iComfort WiFi Thermostat control display.</description>
12+
<channel-groups>
13+
<channel-group id="alertsAndReminders" typeId="alert01" />
14+
</channel-groups>
15+
16+
<properties>
17+
<property name="vendor">Lennox</property>
18+
<property name="systemName"></property>
19+
<property name="gatewaySerialNumber"></property>
20+
<property name="firmwareVersion"></property>
21+
</properties>
22+
<representation-property>gatewaySN</representation-property>
1223
<config-description>
1324
<parameter name="id" type="text" required="true" readOnly="true">
1425
<label>ID</label>
@@ -47,4 +58,18 @@
4758
</parameter>
4859
</config-description>
4960
</thing-type>
61+
62+
<channel-group-type id="alert01">
63+
<label>Gateway Alerts</label>
64+
<description>Alerts and Reminders</description>
65+
<category>HVAC</category>
66+
<channels>
67+
<channel id="AlarmDescription" typeId="alarmDescription" />
68+
<channel id="AlarmNbr" typeId="alarmNbr" />
69+
<channel id="AlarmType" typeId="alarmType" />
70+
<channel id="AlarmStatus" typeId="alarmStatus" />
71+
<channel id="DateTimeSet" typeId="dateTimeSet" />
72+
<channel id="AlertNumber" typeId="alertNumber" />
73+
</channels>
74+
</channel-group-type>
5075
</thing:thing-descriptions>

META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Bundle-Name: iComfortWiFi Binding
77
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
88
Bundle-SymbolicName: org.openhab.binding.icomfortwifi;singleton:=true
99
Bundle-Vendor: openHAB
10-
Bundle-Version: 2.5.0.qualifier
10+
Bundle-Version: 2.5.6.qualifier
1111
Import-Package:
1212
com.google.gson,
1313
com.google.gson.annotations,

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,20 @@ Optional refresh time, default set to 30 seconds.
3232
Bridge icomfortwifi:account:demoaccount "Demo name" @ "Demo location" [ userName = "yourusername", password = "yourpassword", refreshInterval = 60] {}
3333
```
3434

35-
Thing "Thermostat display" - no configuration required (currently unsupported).
35+
Thing "Thermostat display" - no configuration required.
36+
37+
```
38+
Thing thermostat thing_id "Demo thermostat name" @ "Demo thermostat location" [id = "your_gateway_id", name = "Thermostat Name"]
39+
```
40+
41+
## Channels
42+
43+
Alarm_Description - Description of the current alarm (Known valuse "Filter 1", "Humidifier Pad") (Read Only)<br />
44+
Alarm_Code - Code of the alarm (Read Only)<br />
45+
Alarm_Type - Type of the alarm (Read Only)<br />
46+
Alarm_Status - Status of the alarm (Read Only)<br />
47+
Alarm_DateTimeSet - Date and Time alarm was set (Read Only)<br />
48+
Alarm_Number - Curent alarm number to display (up to 20) (Read / Write)<br />
3649

3750
Thing "Zone" - no configuration required, can be added manually or through PaperUI.<br />
3851
For manual addition you need to know your Gateway ID:
@@ -49,7 +62,7 @@ Temperature - Current zone temperature (Read Only)<br />
4962
Humidity - Current zone humidity (Read Only)<br />
5063
SystemStatus - Current system status (Read Only)<br />
5164
OperationMode - Current operation mode (Read / Write)<br />
52-
AwayMode - Current away status (Read / Write)(Note: this is currently under development and requires testing)<br />
65+
AwayMode - Current away status (Read / Write)<br />
5366
FanMode - Current fan mode (Read / Write)<br />
5467
CoolSetPoint - Cool set point for the zone (Read / Write)<br />
5568
HeatSetPoint - Heat set point for the zone (Read / Write)<br />
@@ -62,6 +75,7 @@ Thing example:
6275
```
6376
Bridge icomfortwifi:account:demoaccount "My Acoount" @ "My House" [ userName = "johndoe", password = "supersecret", refreshInterval = 60] {
6477
Thing zone home_zone_1 "Zone 1" @ "Whole House" [ id = "WS12A34567_0", name = "Main Zone" ]
78+
Thing thermostat thermostat_1 "My Thermostat" @ "Whole House" [id = "WS12A34567", name = "My Thermostat"]
6579
}
6680
```
6781

@@ -79,6 +93,16 @@ Number:Temperature Thermostat_Cool_Point "Cool Set Point [%.1f %unit%]" <temp
7993
Number:Temperature Thermostat_Heat_Point "Heat Set Point [%.1f %unit%]" <temperature> (gWholeHouse) {channel="icomfortwifi:zone:demoaccount:home_zone_1:HeatSetPoint"}
8094
```
8195

96+
```
97+
Thermostat items:
98+
String Alarm_Description "Alarm Description [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlarmDescription"}
99+
Number Alarm_Code "Alarm Code [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlarmNbr"}
100+
String Alarm_Type "Alarm Type [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlarmType"}
101+
String Alarm_Status "Alarm Status [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlarmStatus"}
102+
String Alarm_DateTimeSet "Alarm Date Time Set [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#DateTimeSet"}
103+
Number Alarm_Number "Alarm Number [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlertNumber"}
104+
```
105+
82106
Sitemap example:
83107
```
84108
Text item=Thermostat_Temperature
@@ -89,6 +113,14 @@ Switch item=Thermostat_Away_Mode mappings=[AWAY_ON="Away", AWAY_OFF="Not Away"]
89113
Selection item=Thermostat_Fan_Mode mappings=[AUTO="Auto", ON="On", CIRCULATE="Circulate"]
90114
Setpoint item=Thermostat_Cool_Point
91115
Setpoint item=Thermostat_Heat_Point
116+
117+
Text item=Alarm_Description
118+
Text item=Alarm_Code
119+
Text item=Alarm_Type
120+
Text item=Alarm_Status
121+
Text item=Alarm_DateTimeSet
122+
123+
Setpoint item=Alarm_Number
92124
```
93125

94126
## Foot note!

src/main/java/org/openhab/binding/icomfortwifi/handler/BaseiComfortWiFiHandler.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88
*/
99
package org.openhab.binding.icomfortwifi.handler;
1010

11+
import java.time.Instant;
12+
import java.time.ZonedDateTime;
13+
import java.util.Date;
14+
import java.util.TimeZone;
15+
1116
import org.apache.commons.lang.StringUtils;
17+
import org.eclipse.jdt.annotation.Nullable;
18+
import org.eclipse.smarthome.core.library.types.DateTimeType;
1219
import org.eclipse.smarthome.core.thing.Bridge;
1320
import org.eclipse.smarthome.core.thing.Thing;
1421
import org.eclipse.smarthome.core.thing.ThingStatus;
1522
import org.eclipse.smarthome.core.thing.ThingStatusDetail;
1623
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
24+
import org.eclipse.smarthome.core.types.State;
25+
import org.eclipse.smarthome.core.types.UnDefType;
1726
import org.openhab.binding.icomfortwifi.internal.api.models.response.SystemsInfo;
1827
import org.openhab.binding.icomfortwifi.internal.configuration.iComfortWiFiThingConfiguration;
1928

@@ -133,4 +142,14 @@ private void checkConfig() {
133142
}
134143
}
135144

145+
protected State getAsDateTimeTypeOrNull(@Nullable Date date) {
146+
if (date == null) {
147+
return UnDefType.NULL;
148+
}
149+
150+
long offsetMillis = TimeZone.getDefault().getOffset(date.getTime());
151+
Instant instant = date.toInstant().plusMillis(offsetMillis);
152+
return new DateTimeType(ZonedDateTime.ofInstant(instant, TimeZone.getDefault().toZoneId()));
153+
}
154+
136155
}

src/main/java/org/openhab/binding/icomfortwifi/handler/iComfortWiFiBridgeHandler.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.eclipse.smarthome.core.types.Command;
3131
import org.openhab.binding.icomfortwifi.RunnableWithTimeout;
3232
import org.openhab.binding.icomfortwifi.internal.api.iComfortWiFiApiClient;
33+
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.TempUnits;
3334
import org.openhab.binding.icomfortwifi.internal.api.models.response.SystemInfo;
3435
import org.openhab.binding.icomfortwifi.internal.api.models.response.SystemsInfo;
3536
import org.openhab.binding.icomfortwifi.internal.api.models.response.ZoneStatus;
@@ -150,6 +151,11 @@ public void setZoneHeatingPoint(ZoneStatus zoneStatus, double doubleValue) {
150151
updateThings();
151152
}
152153

154+
//
155+
public void setAlternateTemperatureUnit(TempUnits tempUnit) {
156+
this.update(tempUnit);
157+
}
158+
153159
public void addAccountStatusListener(iComfortWiFiAccountStatusListener listener) {
154160
listeners.add(listener);
155161
listener.accountStatusChanged(getThing().getStatus());
@@ -214,6 +220,18 @@ private void update() {
214220
}
215221
}
216222

223+
// Requesting update from the back end in specified unit.
224+
private void update(TempUnits tempUnit) {
225+
try {
226+
apiClient.update(tempUnit);
227+
updateAccountStatus(ThingStatus.ONLINE);
228+
updateThings();
229+
} catch (Exception e) {
230+
updateAccountStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
231+
logger.debug("Failed to update system status", e);
232+
}
233+
}
234+
217235
private void updateAccountStatus(ThingStatus newStatus) {
218236
updateAccountStatus(newStatus, ThingStatusDetail.NONE, null);
219237
}

src/main/java/org/openhab/binding/icomfortwifi/handler/iComfortWiFiHeatingZoneHandler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
package org.openhab.binding.icomfortwifi.handler;
1010

11+
import javax.measure.Unit;
1112
import javax.measure.quantity.Temperature;
1213

1314
import org.eclipse.smarthome.core.library.types.QuantityType;
@@ -23,6 +24,7 @@
2324
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.AwayStatus;
2425
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.FanMode;
2526
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.OperationMode;
27+
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.TempUnits;
2628
import org.openhab.binding.icomfortwifi.internal.api.models.response.ZoneStatus;
2729
import org.slf4j.Logger;
2830
import org.slf4j.LoggerFactory;
@@ -95,6 +97,14 @@ public void handleCommand(ChannelUID channelUID, Command command) {
9597

9698
iComfortWiFiBridgeHandler bridge = getiComfortWiFiBridge();
9799
if (bridge != null) {
100+
// Accommodating the case where Framework units are different from back end.
101+
if (command instanceof QuantityType) {
102+
Unit<Temperature> tempUnit = ((QuantityType<Temperature>) command).getUnit();
103+
if (tempUnit != zoneStatus.preferredTemperatureUnit.getTemperatureUnit()) {
104+
bridge.setAlternateTemperatureUnit(TempUnits.getCustomTemperatureUnit(tempUnit));
105+
}
106+
}
107+
98108
String channelId = channelUID.getId();
99109
if (iComfortWiFiBindingConstants.ZONE_AWAY_MODE_CHANNEL.equals(channelId)) {
100110
bridge.setZoneAwayMode(zoneStatus, AwayStatus.valueOf(command.toString()).getAwayValue());

src/main/java/org/openhab/binding/icomfortwifi/handler/iComfortWiFiTemperatureControlSystemHandler.java

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@
88
*/
99
package org.openhab.binding.icomfortwifi.handler;
1010

11+
import java.util.Map;
12+
13+
import org.eclipse.smarthome.core.library.types.DecimalType;
14+
import org.eclipse.smarthome.core.library.types.StringType;
1115
import org.eclipse.smarthome.core.thing.ChannelUID;
1216
import org.eclipse.smarthome.core.thing.Thing;
1317
import org.eclipse.smarthome.core.thing.ThingStatus;
1418
import org.eclipse.smarthome.core.thing.ThingStatusDetail;
1519
import org.eclipse.smarthome.core.types.Command;
1620
import org.eclipse.smarthome.core.types.RefreshType;
21+
import org.openhab.binding.icomfortwifi.iComfortWiFiBindingConstants;
1722
import org.openhab.binding.icomfortwifi.internal.api.models.response.SystemInfo;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
1825

1926
/**
2027
* Handler for a temperature control system. Gets and sets global system mode.
@@ -23,7 +30,9 @@
2330
*
2431
*/
2532
public class iComfortWiFiTemperatureControlSystemHandler extends BaseiComfortWiFiHandler {
33+
private final Logger logger = LoggerFactory.getLogger(iComfortWiFiTemperatureControlSystemHandler.class);
2634
private SystemInfo systemInfo;
35+
private Integer alertNumber = 0;
2736

2837
public iComfortWiFiTemperatureControlSystemHandler(Thing thing) {
2938
super(thing);
@@ -42,21 +51,47 @@ public void update(SystemInfo systemInfo) {
4251
"Status not found, check the display id");
4352
} else if (handleActiveFaults(systemInfo) == false) {
4453
updateiComfortWiFiThingStatus(ThingStatus.ONLINE);
45-
// updateState(EvohomeBindingConstants.DISPLAY_SYSTEM_MODE_CHANNEL, //Moved to zone status
46-
// new StringType(tcsStatus.getMode().getMode()));
54+
setDeviceProperties(systemInfo);
55+
56+
updateState(iComfortWiFiBindingConstants.TCS_ALARM_DESCRIPTION_CHANNEL, new StringType(
57+
systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).alarmDescription.toString()));
58+
59+
updateState(iComfortWiFiBindingConstants.TCS_ALARM_NBR_CHANNEL,
60+
new DecimalType(systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).alarmNbr));
61+
62+
updateState(iComfortWiFiBindingConstants.TCS_ALARM_TYPE_CHANNEL,
63+
new StringType(systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).alarmType.toString()));
64+
65+
// Set Alarm status
66+
updateState(iComfortWiFiBindingConstants.TCS_ALARM_STATUS_CHANNEL,
67+
new StringType(systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).status.toString()));
68+
69+
updateState(iComfortWiFiBindingConstants.TCS_ALARM_DATE_TIME_SET_CHANNEL,
70+
getAsDateTimeTypeOrNull(systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).dateTimeSet));
71+
72+
updateState(iComfortWiFiBindingConstants.TCS_ALARM_ALERT_NUMBER, new DecimalType(alertNumber));
4773
}
4874
}
4975

76+
private void setDeviceProperties(SystemInfo systemInfo) {
77+
Map<String, String> properties = editProperties();
78+
properties.put(iComfortWiFiBindingConstants.TCS_PROPERTY_SYSTEM_NAME, systemInfo.systemName);
79+
properties.put(iComfortWiFiBindingConstants.TCS_PROPERTY_GATEWAY_SN, systemInfo.gatewaySN);
80+
properties.put(iComfortWiFiBindingConstants.TCS_PROPERTY_FIRMWARE_VERSION, systemInfo.firmwareVersion);
81+
updateProperties(properties);
82+
}
83+
5084
@Override
5185
public void handleCommand(ChannelUID channelUID, Command command) {
86+
logger.debug("Entering TCS Handler for Gateway {}", systemInfo.gatewaySN);
87+
logger.debug("Executing command {}", command.toString());
5288
if (command == RefreshType.REFRESH) {
5389
update(systemInfo);
54-
// } else if (channelUID.getId().equals(iComfortWiFiBindingConstants.DISPLAY_SYSTEM_MODE_CHANNEL)) { //Mode
55-
// channel moved to Zone handler
56-
// iComfortWiFiBridgeHandler bridge = getiComfortWiFiBridge();
57-
// if (bridge != null) {
58-
// bridge.setTcsMode(getiComfortWiFiThingConfig().id, command.toString());
59-
// }
90+
} else if (channelUID.getId().equals(iComfortWiFiBindingConstants.TCS_ALARM_ALERT_NUMBER)
91+
&& command instanceof DecimalType) {
92+
// Handling Alert Number to display
93+
alertNumber = ((DecimalType) command).intValue();
94+
update(systemInfo);
6095
}
6196
}
6297

0 commit comments

Comments
 (0)