Skip to content

Commit

Permalink
Add reporting configuration/mark channel as advanced
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Christian <[email protected]>
  • Loading branch information
lucasec committed Jun 5, 2022
1 parent cecefac commit e7e7939
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@
import com.zsmartsystems.zigbee.zcl.ZclAttributeListener;
import com.zsmartsystems.zigbee.zcl.clusters.ZclThermostatCluster;
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType;
import org.eclipse.jdt.annotation.NonNull;
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.binding.zigbee.internal.converter.config.ZclReportingConfig;
import org.openhab.core.config.core.Configuration;
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.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;

Expand All @@ -43,8 +47,13 @@
public class ZigBeeConverterThermostatPiCoolingDemand extends ZigBeeBaseChannelConverter implements ZclAttributeListener {
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterThermostatPiCoolingDemand.class);

private static BigDecimal CHANGE_DEFAULT = new BigDecimal(1);
private static BigDecimal CHANGE_MIN = new BigDecimal(1);
private static BigDecimal CHANGE_MAX = new BigDecimal(100);

private ZclThermostatCluster cluster;
private ZclAttribute attribute;
private ZclReportingConfig configReporting;

@Override
public Set<Integer> getImplementedClientClusters() {
Expand All @@ -65,14 +74,17 @@ public boolean initializeDevice() {
return false;
}

ZclReportingConfig reporting = new ZclReportingConfig(channel);

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);

CommandResult reportingResponse = attribute.setReporting(reporting.getReportingTimeMin(),
reporting.getReportingTimeMax(), reporting.getReportingChange()).get();
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, reporting.getPollingPeriod());
} else {
logger.debug("{}: Failed to bind thermostat cluster", endpoint.getIeeeAddress());
}
Expand All @@ -98,6 +110,12 @@ public boolean initializeConverter(ZigBeeThingHandler thing) {
return false;
}

// Add reporting configuration
configReporting = new ZclReportingConfig(channel);
configReporting.setAnalogue(CHANGE_DEFAULT, CHANGE_MIN, CHANGE_MAX);
configOptions = new ArrayList<>();
configOptions.addAll(configReporting.getConfiguration());

// Add a listener, then request the status
cluster.addAttributeListener(this);
return true;
Expand All @@ -108,11 +126,34 @@ public void disposeConverter() {
cluster.removeAttributeListener(this);
}

@Override
public int getPollingPeriod() {
return configReporting.getPollingPeriod();
}

@Override
public void handleRefresh() {
attribute.readValue(0);
}

@Override
public void updateConfiguration(@NonNull final Configuration currentConfiguration,
final Map<String, Object> updatedParameters) {

if (configReporting.updateConfiguration(currentConfiguration, updatedParameters)) {
try {
final ZclAttribute attribute = cluster.getAttribute(ZclThermostatCluster.ATTR_PICOOLINGDEMAND);

final CommandResult reportingResponse = attribute.setReporting(configReporting.getReportingTimeMin(),
configReporting.getReportingTimeMax(), configReporting.getReportingChange()).get();
handleReportingResponse(reportingResponse, configReporting.getPollingPeriod(),
configReporting.getReportingTimeMax());
} catch (InterruptedException | ExecutionException e) {
logger.debug("{}: Thermostat PI cooling demand exception setting reporting", endpoint.getIeeeAddress(), e);
}
}
}

@Override
public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) {
ZclThermostatCluster cluster = (ZclThermostatCluster) endpoint.getInputCluster(ZclThermostatCluster.CLUSTER_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,22 @@
import com.zsmartsystems.zigbee.zcl.ZclAttributeListener;
import com.zsmartsystems.zigbee.zcl.clusters.ZclThermostatCluster;
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType;
import org.eclipse.jdt.annotation.NonNull;
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.binding.zigbee.internal.converter.config.ZclReportingConfig;
import org.openhab.core.config.core.Configuration;
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.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;

Expand All @@ -49,8 +47,13 @@
public class ZigBeeConverterThermostatPiHeatingDemand extends ZigBeeBaseChannelConverter implements ZclAttributeListener {
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterThermostatPiHeatingDemand.class);

private static BigDecimal CHANGE_DEFAULT = new BigDecimal(1);
private static BigDecimal CHANGE_MIN = new BigDecimal(1);
private static BigDecimal CHANGE_MAX = new BigDecimal(100);

private ZclThermostatCluster cluster;
private ZclAttribute attribute;
private ZclReportingConfig configReporting;

@Override
public Set<Integer> getImplementedClientClusters() {
Expand All @@ -71,14 +74,17 @@ public boolean initializeDevice() {
return false;
}

ZclReportingConfig reporting = new ZclReportingConfig(channel);

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);

CommandResult reportingResponse = attribute.setReporting(reporting.getReportingTimeMin(),
reporting.getReportingTimeMax(), reporting.getReportingChange()).get();
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, reporting.getPollingPeriod());
} else {
logger.debug("{}: Failed to bind thermostat cluster", endpoint.getIeeeAddress());
}
Expand All @@ -104,6 +110,12 @@ public boolean initializeConverter(ZigBeeThingHandler thing) {
return false;
}

// Add reporting configuration
configReporting = new ZclReportingConfig(channel);
configReporting.setAnalogue(CHANGE_DEFAULT, CHANGE_MIN, CHANGE_MAX);
configOptions = new ArrayList<>();
configOptions.addAll(configReporting.getConfiguration());

// Add a listener, then request the status
cluster.addAttributeListener(this);
return true;
Expand All @@ -114,11 +126,34 @@ public void disposeConverter() {
cluster.removeAttributeListener(this);
}

@Override
public int getPollingPeriod() {
return configReporting.getPollingPeriod();
}

@Override
public void handleRefresh() {
attribute.readValue(0);
}

@Override
public void updateConfiguration(@NonNull final Configuration currentConfiguration,
final Map<String, Object> updatedParameters) {

if (configReporting.updateConfiguration(currentConfiguration, updatedParameters)) {
try {
final ZclAttribute attribute = cluster.getAttribute(ZclThermostatCluster.ATTR_PIHEATINGDEMAND);

final CommandResult reportingResponse = attribute.setReporting(configReporting.getReportingTimeMin(),
configReporting.getReportingTimeMax(), configReporting.getReportingChange()).get();
handleReportingResponse(reportingResponse, configReporting.getPollingPeriod(),
configReporting.getReportingTimeMax());
} catch (InterruptedException | ExecutionException e) {
logger.debug("{}: Thermostat PI heating demand exception setting reporting", endpoint.getIeeeAddress(), e);
}
}
}

@Override
public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) {
ZclThermostatCluster cluster = (ZclThermostatCluster) endpoint.getInputCluster(ZclThermostatCluster.CLUSTER_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
</channel-type>

<!-- Thermostat Heating Demand -->
<channel-type id="thermostat_heatingdemand">
<channel-type id="thermostat_heatingdemand" advanced="true">
<item-type>Number:Dimensionless</item-type>
<label>Heating Demand</label>
<description>The level of heating currently demanded by the thermostat</description>
Expand All @@ -390,7 +390,7 @@
</channel-type>

<!-- Thermostat Cooling Demand -->
<channel-type id="thermostat_coolingdemand">
<channel-type id="thermostat_coolingdemand" advanced="true">
<item-type>Number:Dimensionless</item-type>
<label>Cooling Demand</label>
<description>The level of cooling currently demanded by the thermostat</description>
Expand Down

0 comments on commit e7e7939

Please sign in to comment.