Skip to content

Commit

Permalink
Added support for Thermostat thing with Alert channels.
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Panchenko <[email protected]>
  • Loading branch information
kpanchen committed May 6, 2019
1 parent 7004c78 commit 5299aa4
Show file tree
Hide file tree
Showing 15 changed files with 449 additions and 16 deletions.
58 changes: 56 additions & 2 deletions ESH-INF/thing/channels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</state>
</channel-type>

<channel-type id="fanMode">
<channel-type id="fanMode">
<item-type>String</item-type>
<label>Fan Mode Status</label>
<description>Current fan mode status</description>
Expand Down Expand Up @@ -84,11 +84,65 @@
<state step="0.5" pattern="%.1f %unit%" readOnly="false"/>
</channel-type>

<channel-type id="heatSetPoint">
<channel-type id="heatSetPoint">
<item-type>Number:Temperature</item-type>
<label>Heat Set Point</label>
<description>Gets or sets the heat set point of this zone.</description>
<category>Temperature</category>
<state step="0.5" pattern="%.1f %unit%" readOnly="false"/>
</channel-type>

<channel-type id="alarmDescription">
<item-type>String</item-type>
<label>Alarm Description</label>
<description>Description of alarm being raised.</description>
<category>Text</category>
<state readOnly="true"/>
</channel-type>

<channel-type id="alarmNbr">
<item-type>Number</item-type>
<label>Alarm Code</label>
<description>Code of alarm being raised.</description>
<category>Number</category>
<state readOnly="true"/>
</channel-type>

<channel-type id="alarmType">
<item-type>String</item-type>
<label>Alarm Type</label>
<description>Type of alarm being raised.</description>
<category>Text</category>
<state readOnly="true"/>
</channel-type>

<channel-type id="alarmStatus">
<item-type>String</item-type>
<label>Alarm Status</label>
<description>Status of the alarm.</description>
<category>Text</category>
<state pattern="%s" readOnly="true">
<options>
<option value="ALERT_CLEARED">Alert has been cleared</option>
<option value="ALERT_RAISED">Alert is active</option>
</options>
</state>
</channel-type>

<channel-type id="dateTimeSet">
<item-type>DateTime</item-type>
<label>Alarm Date Set</label>
<description>Date and Time when alarm was raised.</description>
<category>DateTime</category>
<state readOnly="true"/>
</channel-type>

<channel-type id="alertNumber">
<item-type>Number</item-type>
<label>Alert Number</label>
<description>Display alert with specified number (up to 20).</description>
<category>Alert Number</category>
<state readOnly="false" min="0" max="20"/>
</channel-type>

</thing:thing-descriptions>
25 changes: 25 additions & 0 deletions ESH-INF/thing/thing-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
</supported-bridge-type-refs>
<label>iComfort WiFi Thermostat</label>
<description>This represents the iComfort WiFi Thermostat control display.</description>
<channel-groups>
<channel-group id="alertsAndReminders" typeId="alert01" />
</channel-groups>

<properties>
<property name="vendor">Lennox</property>
<property name="systemName"></property>
<property name="gatewaySerialNumber"></property>
<property name="firmwareVersion"></property>
</properties>
<representation-property>gatewaySN</representation-property>
<config-description>
<parameter name="id" type="text" required="true" readOnly="true">
<label>ID</label>
Expand Down Expand Up @@ -47,4 +58,18 @@
</parameter>
</config-description>
</thing-type>

<channel-group-type id="alert01">
<label>Gateway Alerts</label>
<description>Alerts and Reminders</description>
<category>HVAC</category>
<channels>
<channel id="AlarmDescription" typeId="alarmDescription" />
<channel id="AlarmNbr" typeId="alarmNbr" />
<channel id="AlarmType" typeId="alarmType" />
<channel id="AlarmStatus" typeId="alarmStatus" />
<channel id="DateTimeSet" typeId="dateTimeSet" />
<channel id="AlertNumber" typeId="alertNumber" />
</channels>
</channel-group-type>
</thing:thing-descriptions>
2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Bundle-Name: iComfortWiFi Binding
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: org.openhab.binding.icomfortwifi;singleton:=true
Bundle-Vendor: openHAB
Bundle-Version: 2.5.0.qualifier
Bundle-Version: 2.5.6.qualifier
Import-Package:
com.google.gson,
com.google.gson.annotations,
Expand Down
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,20 @@ Optional refresh time, default set to 30 seconds.
Bridge icomfortwifi:account:demoaccount "Demo name" @ "Demo location" [ userName = "yourusername", password = "yourpassword", refreshInterval = 60] {}
```

Thing "Thermostat display" - no configuration required (currently unsupported).
Thing "Thermostat display" - no configuration required.

```
Thing thermostat thing_id "Demo thermostat name" @ "Demo thermostat location" [id = "your_gateway_id", name = "Thermostat Name"]
```

## Channels

Alarm_Description - Description of the current alarm (Known valuse "Filter 1", "Humidifier Pad") (Read Only)<br />
Alarm_Code - Code of the alarm (Read Only)<br />
Alarm_Type - Type of the alarm (Read Only)<br />
Alarm_Status - Status of the alarm (Read Only)<br />
Alarm_DateTimeSet - Date and Time alarm was set (Read Only)<br />
Alarm_Number - Curent alarm number to display (up to 20) (Read / Write)<br />

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

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

```
Thermostat items:
String Alarm_Description "Alarm Description [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlarmDescription"}
Number Alarm_Code "Alarm Code [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlarmNbr"}
String Alarm_Type "Alarm Type [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlarmType"}
String Alarm_Status "Alarm Status [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlarmStatus"}
String Alarm_DateTimeSet "Alarm Date Time Set [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#DateTimeSet"}
Number Alarm_Number "Alarm Number [%s]" <alarm> (gWholeHouse) {channel="icomfortwifi:thermostat:demoaccount:thermostat_1:alertsAndReminders#AlertNumber"}
```

Sitemap example:
```
Text item=Thermostat_Temperature
Expand All @@ -89,6 +113,14 @@ Switch item=Thermostat_Away_Mode mappings=[AWAY_ON="Away", AWAY_OFF="Not Away"]
Selection item=Thermostat_Fan_Mode mappings=[AUTO="Auto", ON="On", CIRCULATE="Circulate"]
Setpoint item=Thermostat_Cool_Point
Setpoint item=Thermostat_Heat_Point
Text item=Alarm_Description
Text item=Alarm_Code
Text item=Alarm_Type
Text item=Alarm_Status
Text item=Alarm_DateTimeSet
Setpoint item=Alarm_Number
```

## Foot note!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@
*/
package org.openhab.binding.icomfortwifi.handler;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.TimeZone;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.library.types.DateTimeType;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.ThingStatusDetail;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.UnDefType;
import org.openhab.binding.icomfortwifi.internal.api.models.response.SystemsInfo;
import org.openhab.binding.icomfortwifi.internal.configuration.iComfortWiFiThingConfiguration;

Expand Down Expand Up @@ -133,4 +142,14 @@ private void checkConfig() {
}
}

protected State getAsDateTimeTypeOrNull(@Nullable Date date) {
if (date == null) {
return UnDefType.NULL;
}

long offsetMillis = TimeZone.getDefault().getOffset(date.getTime());
Instant instant = date.toInstant().plusMillis(offsetMillis);
return new DateTimeType(ZonedDateTime.ofInstant(instant, TimeZone.getDefault().toZoneId()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.smarthome.core.types.Command;
import org.openhab.binding.icomfortwifi.RunnableWithTimeout;
import org.openhab.binding.icomfortwifi.internal.api.iComfortWiFiApiClient;
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.TempUnits;
import org.openhab.binding.icomfortwifi.internal.api.models.response.SystemInfo;
import org.openhab.binding.icomfortwifi.internal.api.models.response.SystemsInfo;
import org.openhab.binding.icomfortwifi.internal.api.models.response.ZoneStatus;
Expand Down Expand Up @@ -150,6 +151,11 @@ public void setZoneHeatingPoint(ZoneStatus zoneStatus, double doubleValue) {
updateThings();
}

//
public void setAlternateTemperatureUnit(TempUnits tempUnit) {
this.update(tempUnit);
}

public void addAccountStatusListener(iComfortWiFiAccountStatusListener listener) {
listeners.add(listener);
listener.accountStatusChanged(getThing().getStatus());
Expand Down Expand Up @@ -214,6 +220,18 @@ private void update() {
}
}

// Requesting update from the back end in specified unit.
private void update(TempUnits tempUnit) {
try {
apiClient.update(tempUnit);
updateAccountStatus(ThingStatus.ONLINE);
updateThings();
} catch (Exception e) {
updateAccountStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
logger.debug("Failed to update system status", e);
}
}

private void updateAccountStatus(ThingStatus newStatus) {
updateAccountStatus(newStatus, ThingStatusDetail.NONE, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.openhab.binding.icomfortwifi.handler;

import javax.measure.Unit;
import javax.measure.quantity.Temperature;

import org.eclipse.smarthome.core.library.types.QuantityType;
Expand All @@ -23,6 +24,7 @@
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.AwayStatus;
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.FanMode;
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.OperationMode;
import org.openhab.binding.icomfortwifi.internal.api.models.response.CustomTypes.TempUnits;
import org.openhab.binding.icomfortwifi.internal.api.models.response.ZoneStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -95,6 +97,14 @@ public void handleCommand(ChannelUID channelUID, Command command) {

iComfortWiFiBridgeHandler bridge = getiComfortWiFiBridge();
if (bridge != null) {
// Accommodating the case where Framework units are different from back end.
if (command instanceof QuantityType) {
Unit<Temperature> tempUnit = ((QuantityType<Temperature>) command).getUnit();
if (tempUnit != zoneStatus.preferredTemperatureUnit.getTemperatureUnit()) {
bridge.setAlternateTemperatureUnit(TempUnits.getCustomTemperatureUnit(tempUnit));
}
}

String channelId = channelUID.getId();
if (iComfortWiFiBindingConstants.ZONE_AWAY_MODE_CHANNEL.equals(channelId)) {
bridge.setZoneAwayMode(zoneStatus, AwayStatus.valueOf(command.toString()).getAwayValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
*/
package org.openhab.binding.icomfortwifi.handler;

import java.util.Map;

import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.ThingStatusDetail;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.openhab.binding.icomfortwifi.iComfortWiFiBindingConstants;
import org.openhab.binding.icomfortwifi.internal.api.models.response.SystemInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Handler for a temperature control system. Gets and sets global system mode.
Expand All @@ -23,7 +30,9 @@
*
*/
public class iComfortWiFiTemperatureControlSystemHandler extends BaseiComfortWiFiHandler {
private final Logger logger = LoggerFactory.getLogger(iComfortWiFiTemperatureControlSystemHandler.class);
private SystemInfo systemInfo;
private Integer alertNumber = 0;

public iComfortWiFiTemperatureControlSystemHandler(Thing thing) {
super(thing);
Expand All @@ -42,21 +51,47 @@ public void update(SystemInfo systemInfo) {
"Status not found, check the display id");
} else if (handleActiveFaults(systemInfo) == false) {
updateiComfortWiFiThingStatus(ThingStatus.ONLINE);
// updateState(EvohomeBindingConstants.DISPLAY_SYSTEM_MODE_CHANNEL, //Moved to zone status
// new StringType(tcsStatus.getMode().getMode()));
setDeviceProperties(systemInfo);

updateState(iComfortWiFiBindingConstants.TCS_ALARM_DESCRIPTION_CHANNEL, new StringType(
systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).alarmDescription.toString()));

updateState(iComfortWiFiBindingConstants.TCS_ALARM_NBR_CHANNEL,
new DecimalType(systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).alarmNbr));

updateState(iComfortWiFiBindingConstants.TCS_ALARM_TYPE_CHANNEL,
new StringType(systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).alarmType.toString()));

// Set Alarm status
updateState(iComfortWiFiBindingConstants.TCS_ALARM_STATUS_CHANNEL,
new StringType(systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).status.toString()));

updateState(iComfortWiFiBindingConstants.TCS_ALARM_DATE_TIME_SET_CHANNEL,
getAsDateTimeTypeOrNull(systemInfo.getGatewaysAlerts().systemAlert.get(alertNumber).dateTimeSet));

updateState(iComfortWiFiBindingConstants.TCS_ALARM_ALERT_NUMBER, new DecimalType(alertNumber));
}
}

private void setDeviceProperties(SystemInfo systemInfo) {
Map<String, String> properties = editProperties();
properties.put(iComfortWiFiBindingConstants.TCS_PROPERTY_SYSTEM_NAME, systemInfo.systemName);
properties.put(iComfortWiFiBindingConstants.TCS_PROPERTY_GATEWAY_SN, systemInfo.gatewaySN);
properties.put(iComfortWiFiBindingConstants.TCS_PROPERTY_FIRMWARE_VERSION, systemInfo.firmwareVersion);
updateProperties(properties);
}

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("Entering TCS Handler for Gateway {}", systemInfo.gatewaySN);
logger.debug("Executing command {}", command.toString());
if (command == RefreshType.REFRESH) {
update(systemInfo);
// } else if (channelUID.getId().equals(iComfortWiFiBindingConstants.DISPLAY_SYSTEM_MODE_CHANNEL)) { //Mode
// channel moved to Zone handler
// iComfortWiFiBridgeHandler bridge = getiComfortWiFiBridge();
// if (bridge != null) {
// bridge.setTcsMode(getiComfortWiFiThingConfig().id, command.toString());
// }
} else if (channelUID.getId().equals(iComfortWiFiBindingConstants.TCS_ALARM_ALERT_NUMBER)
&& command instanceof DecimalType) {
// Handling Alert Number to display
alertNumber = ((DecimalType) command).intValue();
update(systemInfo);
}
}

Expand Down
Loading

0 comments on commit 5299aa4

Please sign in to comment.