-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PI Heating/Cooling Demand Channels.
This adds the "PI Heating Demand" and "PI Cooling Demand" standard thermostat channels. These channels are represented as a percentage (Dimensionless unit), and indicate whether there is a current heating or cooling call from the thermostat. They are fully supported by auto-discovery for the generic device type. Signed-off-by: Lucas Christian <[email protected]>
- Loading branch information
Showing
7 changed files
with
349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
...g/openhab/binding/zigbee/internal/converter/ZigBeeConverterThermostatPiCoolingDemand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/** | ||
* Copyright (c) 2010-2022 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.zigbee.internal.converter; | ||
|
||
import com.zsmartsystems.zigbee.CommandResult; | ||
import com.zsmartsystems.zigbee.ZigBeeEndpoint; | ||
import com.zsmartsystems.zigbee.zcl.ZclAttribute; | ||
import com.zsmartsystems.zigbee.zcl.ZclAttributeListener; | ||
import com.zsmartsystems.zigbee.zcl.clusters.ZclThermostatCluster; | ||
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType; | ||
import org.openhab.binding.zigbee.ZigBeeBindingConstants; | ||
import org.openhab.binding.zigbee.converter.ZigBeeBaseChannelConverter; | ||
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler; | ||
import org.openhab.core.library.types.DecimalType; | ||
import org.openhab.core.thing.Channel; | ||
import org.openhab.core.thing.ThingUID; | ||
import org.openhab.core.thing.binding.builder.ChannelBuilder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
/** | ||
* Converter for the thermostat PI cooling demand channel. The PI Cooling Demand attribute specifies the level | ||
* of cooling currently demanded by the thermostat. | ||
* | ||
* @author Lucas Christian | ||
* | ||
*/ | ||
public class ZigBeeConverterThermostatPiCoolingDemand extends ZigBeeBaseChannelConverter implements ZclAttributeListener { | ||
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterThermostatPiCoolingDemand.class); | ||
|
||
private ZclThermostatCluster cluster; | ||
private ZclAttribute attribute; | ||
|
||
@Override | ||
public Set<Integer> getImplementedClientClusters() { | ||
return Collections.singleton(ZclThermostatCluster.CLUSTER_ID); | ||
} | ||
|
||
@Override | ||
public Set<Integer> getImplementedServerClusters() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public boolean initializeDevice() { | ||
ZclThermostatCluster serverCluster = (ZclThermostatCluster) endpoint | ||
.getInputCluster(ZclThermostatCluster.CLUSTER_ID); | ||
if (serverCluster == null) { | ||
logger.error("{}: Error opening device thermostat cluster", endpoint.getIeeeAddress()); | ||
return false; | ||
} | ||
|
||
try { | ||
CommandResult bindResponse = bind(serverCluster).get(); | ||
if (bindResponse.isSuccess()) { | ||
// Configure reporting | ||
ZclAttribute attribute = serverCluster.getAttribute(ZclThermostatCluster.ATTR_PICOOLINGDEMAND); | ||
CommandResult reportingResponse = attribute | ||
.setReporting(REPORTING_PERIOD_DEFAULT_MIN, REPORTING_PERIOD_DEFAULT_MAX, 1).get(); | ||
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, REPORTING_PERIOD_DEFAULT_MAX); | ||
} else { | ||
logger.debug("{}: Failed to bind thermostat cluster", endpoint.getIeeeAddress()); | ||
} | ||
} catch (InterruptedException | ExecutionException e) { | ||
logger.error("{}: Exception setting reporting ", endpoint.getIeeeAddress(), e); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean initializeConverter(ZigBeeThingHandler thing) { | ||
super.initializeConverter(thing); | ||
cluster = (ZclThermostatCluster) endpoint.getInputCluster(ZclThermostatCluster.CLUSTER_ID); | ||
if (cluster == null) { | ||
logger.error("{}: Error opening device thermostat cluster", endpoint.getIeeeAddress()); | ||
return false; | ||
} | ||
|
||
attribute = cluster.getAttribute(ZclThermostatCluster.ATTR_PICOOLINGDEMAND); | ||
if (attribute == null) { | ||
logger.error("{}: Error opening device thermostat PI cooling demand attribute", endpoint.getIeeeAddress()); | ||
return false; | ||
} | ||
|
||
// Add a listener, then request the status | ||
cluster.addAttributeListener(this); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void disposeConverter() { | ||
cluster.removeAttributeListener(this); | ||
} | ||
|
||
@Override | ||
public void handleRefresh() { | ||
attribute.readValue(0); | ||
} | ||
|
||
@Override | ||
public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) { | ||
ZclThermostatCluster cluster = (ZclThermostatCluster) endpoint.getInputCluster(ZclThermostatCluster.CLUSTER_ID); | ||
if (cluster == null) { | ||
logger.trace("{}: Thermostat cluster not found", endpoint.getIeeeAddress()); | ||
return null; | ||
} | ||
|
||
// Try to read the setpoint attribute | ||
ZclAttribute attribute = cluster.getAttribute(ZclThermostatCluster.ATTR_PICOOLINGDEMAND); | ||
Object value = attribute.readValue(Long.MAX_VALUE); | ||
if (value == null) { | ||
logger.trace("{}: Thermostat PI cooling demand returned null", endpoint.getIeeeAddress()); | ||
return null; | ||
} | ||
|
||
return ChannelBuilder | ||
.create(createChannelUID(thingUID, endpoint, ZigBeeBindingConstants.CHANNEL_NAME_THERMOSTAT_COOLING_DEMAND), | ||
ZigBeeBindingConstants.ITEM_TYPE_NUMBER) | ||
.withType(ZigBeeBindingConstants.CHANNEL_THERMOSTAT_COOLING_DEMAND) | ||
.withLabel(ZigBeeBindingConstants.CHANNEL_LABEL_THERMOSTAT_COOLING_DEMAND) | ||
.withProperties(createProperties(endpoint)).build(); | ||
} | ||
|
||
@Override | ||
public void attributeUpdated(ZclAttribute attribute, Object val) { | ||
logger.debug("{}: ZigBee attribute reports {}", endpoint.getIeeeAddress(), attribute); | ||
if (attribute.getClusterType() == ZclClusterType.THERMOSTAT | ||
&& attribute.getId() == ZclThermostatCluster.ATTR_PICOOLINGDEMAND) { | ||
Integer value = (Integer) val; | ||
updateChannelState(valueToPercentDimensionless(value)); | ||
} | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
...g/openhab/binding/zigbee/internal/converter/ZigBeeConverterThermostatPiHeatingDemand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/** | ||
* Copyright (c) 2010-2022 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.zigbee.internal.converter; | ||
|
||
import com.zsmartsystems.zigbee.CommandResult; | ||
import com.zsmartsystems.zigbee.ZigBeeEndpoint; | ||
import com.zsmartsystems.zigbee.zcl.ZclAttribute; | ||
import com.zsmartsystems.zigbee.zcl.ZclAttributeListener; | ||
import com.zsmartsystems.zigbee.zcl.clusters.ZclThermostatCluster; | ||
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType; | ||
import org.openhab.binding.zigbee.ZigBeeBindingConstants; | ||
import org.openhab.binding.zigbee.converter.ZigBeeBaseChannelConverter; | ||
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler; | ||
import org.openhab.core.library.types.DecimalType; | ||
import org.openhab.core.library.types.OnOffType; | ||
import org.openhab.core.thing.Channel; | ||
import org.openhab.core.thing.ThingUID; | ||
import org.openhab.core.thing.binding.builder.ChannelBuilder; | ||
import org.openhab.core.types.Command; | ||
import org.openhab.core.types.StateDescriptionFragmentBuilder; | ||
import org.openhab.core.types.StateOption; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
/** | ||
* Converter for the thermostat PI heating demand channel. The PI Heating Demand attribute specifies the level | ||
* of heating currently demanded by the thermostat. | ||
* | ||
* @author Lucas Christian | ||
* | ||
*/ | ||
public class ZigBeeConverterThermostatPiHeatingDemand extends ZigBeeBaseChannelConverter implements ZclAttributeListener { | ||
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterThermostatPiHeatingDemand.class); | ||
|
||
private ZclThermostatCluster cluster; | ||
private ZclAttribute attribute; | ||
|
||
@Override | ||
public Set<Integer> getImplementedClientClusters() { | ||
return Collections.singleton(ZclThermostatCluster.CLUSTER_ID); | ||
} | ||
|
||
@Override | ||
public Set<Integer> getImplementedServerClusters() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
@Override | ||
public boolean initializeDevice() { | ||
ZclThermostatCluster serverCluster = (ZclThermostatCluster) endpoint | ||
.getInputCluster(ZclThermostatCluster.CLUSTER_ID); | ||
if (serverCluster == null) { | ||
logger.error("{}: Error opening device thermostat cluster", endpoint.getIeeeAddress()); | ||
return false; | ||
} | ||
|
||
try { | ||
CommandResult bindResponse = bind(serverCluster).get(); | ||
if (bindResponse.isSuccess()) { | ||
// Configure reporting | ||
ZclAttribute attribute = serverCluster.getAttribute(ZclThermostatCluster.ATTR_PIHEATINGDEMAND); | ||
CommandResult reportingResponse = attribute | ||
.setReporting(REPORTING_PERIOD_DEFAULT_MIN, REPORTING_PERIOD_DEFAULT_MAX, 1).get(); | ||
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, REPORTING_PERIOD_DEFAULT_MAX); | ||
} else { | ||
logger.debug("{}: Failed to bind thermostat cluster", endpoint.getIeeeAddress()); | ||
} | ||
} catch (InterruptedException | ExecutionException e) { | ||
logger.error("{}: Exception setting reporting ", endpoint.getIeeeAddress(), e); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean initializeConverter(ZigBeeThingHandler thing) { | ||
super.initializeConverter(thing); | ||
cluster = (ZclThermostatCluster) endpoint.getInputCluster(ZclThermostatCluster.CLUSTER_ID); | ||
if (cluster == null) { | ||
logger.error("{}: Error opening device thermostat cluster", endpoint.getIeeeAddress()); | ||
return false; | ||
} | ||
|
||
attribute = cluster.getAttribute(ZclThermostatCluster.ATTR_PIHEATINGDEMAND); | ||
if (attribute == null) { | ||
logger.error("{}: Error opening device thermostat PI heating demand attribute", endpoint.getIeeeAddress()); | ||
return false; | ||
} | ||
|
||
// Add a listener, then request the status | ||
cluster.addAttributeListener(this); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void disposeConverter() { | ||
cluster.removeAttributeListener(this); | ||
} | ||
|
||
@Override | ||
public void handleRefresh() { | ||
attribute.readValue(0); | ||
} | ||
|
||
@Override | ||
public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) { | ||
ZclThermostatCluster cluster = (ZclThermostatCluster) endpoint.getInputCluster(ZclThermostatCluster.CLUSTER_ID); | ||
if (cluster == null) { | ||
logger.trace("{}: Thermostat cluster not found", endpoint.getIeeeAddress()); | ||
return null; | ||
} | ||
|
||
// Try to read the setpoint attribute | ||
ZclAttribute attribute = cluster.getAttribute(ZclThermostatCluster.ATTR_PIHEATINGDEMAND); | ||
Object value = attribute.readValue(Long.MAX_VALUE); | ||
if (value == null) { | ||
logger.trace("{}: Thermostat PI heating demand returned null", endpoint.getIeeeAddress()); | ||
return null; | ||
} | ||
|
||
return ChannelBuilder | ||
.create(createChannelUID(thingUID, endpoint, ZigBeeBindingConstants.CHANNEL_NAME_THERMOSTAT_HEATING_DEMAND), | ||
ZigBeeBindingConstants.ITEM_TYPE_NUMBER) | ||
.withType(ZigBeeBindingConstants.CHANNEL_THERMOSTAT_HEATING_DEMAND) | ||
.withLabel(ZigBeeBindingConstants.CHANNEL_LABEL_THERMOSTAT_HEATING_DEMAND) | ||
.withProperties(createProperties(endpoint)).build(); | ||
} | ||
|
||
@Override | ||
public void attributeUpdated(ZclAttribute attribute, Object val) { | ||
logger.debug("{}: ZigBee attribute reports {}", endpoint.getIeeeAddress(), attribute); | ||
if (attribute.getClusterType() == ZclClusterType.THERMOSTAT | ||
&& attribute.getId() == ZclThermostatCluster.ATTR_PIHEATINGDEMAND) { | ||
Integer value = (Integer) val; | ||
updateChannelState(valueToPercentDimensionless(value)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters