Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ZigBee library deprecations from a number of converters #713

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import javax.measure.quantity.Power;

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.QuantityType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.converter.ZigBeeBaseChannelConverter;
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,6 +35,7 @@
import com.zsmartsystems.zigbee.zcl.ZclAttribute;
import com.zsmartsystems.zigbee.zcl.ZclAttributeListener;
import com.zsmartsystems.zigbee.zcl.clusters.ZclElectricalMeasurementCluster;
import com.zsmartsystems.zigbee.zcl.clusters.ZclRelativeHumidityMeasurementCluster;
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType;

/**
Expand All @@ -46,6 +47,7 @@ public class ZigBeeConverterMeasurementPower extends ZigBeeBaseChannelConverter
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterMeasurementPower.class);

private ZclElectricalMeasurementCluster clusterMeasurement;
private ZclAttribute attribute;

private Integer divisor;
private Integer multiplier;
Expand Down Expand Up @@ -74,11 +76,10 @@ public boolean initializeDevice() {
try {
CommandResult bindResponse = bind(serverClusterMeasurement).get();
if (bindResponse.isSuccess()) {
// Configure reporting
ZclAttribute attribute = serverClusterMeasurement
.getAttribute(ZclElectricalMeasurementCluster.ATTR_ACTIVEPOWER);
// Configure reporting - no faster than once per second - no slower than 2 hours.
CommandResult reportingResponse = serverClusterMeasurement
.setReporting(attribute, 3, REPORTING_PERIOD_DEFAULT_MAX, 1).get();
CommandResult reportingResponse = attribute.setReporting(3, REPORTING_PERIOD_DEFAULT_MAX, 1).get();
handleReportingResponse(reportingResponse, POLLING_PERIOD_HIGH, REPORTING_PERIOD_DEFAULT_MAX);
} else {
pollingPeriod = POLLING_PERIOD_HIGH;
Expand All @@ -101,6 +102,12 @@ public boolean initializeConverter(ZigBeeThingHandler thing) {
return false;
}

attribute = clusterMeasurement.getAttribute(ZclRelativeHumidityMeasurementCluster.ATTR_MEASUREDVALUE);
if (attribute == null) {
logger.error("{}: Error opening device measured value attribute", endpoint.getIeeeAddress());
return false;
}

determineDivisorAndMultiplier(clusterMeasurement);

// Add a listener, then request the status
Expand All @@ -117,7 +124,7 @@ public void disposeConverter() {

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

@Override
Expand All @@ -129,21 +136,10 @@ public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) {
return null;
}

try {
if (!cluster.discoverAttributes(false).get()
&& !cluster.isAttributeSupported(ZclElectricalMeasurementCluster.ATTR_ACTIVEPOWER)) {
logger.trace("{}: Electrical measurement cluster active power not supported",
endpoint.getIeeeAddress());

return null;
} else if (cluster.getActivePower(Long.MAX_VALUE) == null) {
logger.trace("{}: Electrical measurement cluster active power returned null",
endpoint.getIeeeAddress());
return null;
}
} catch (InterruptedException | ExecutionException e) {
logger.warn("{}: Exception discovering attributes in electrical measurement cluster",
endpoint.getIeeeAddress(), e);
ZclAttribute attribute = cluster.getAttribute(ZclElectricalMeasurementCluster.ATTR_ACTIVEPOWER);
Object value = attribute.readValue(Long.MAX_VALUE);
if (value == null) {
logger.trace("{}: Electrical measurement cluster active power returned null", endpoint.getIeeeAddress());
return null;
}

Expand All @@ -168,8 +164,13 @@ public void attributeUpdated(ZclAttribute attribute, Object val) {
}

private void determineDivisorAndMultiplier(ZclElectricalMeasurementCluster serverClusterMeasurement) {
divisor = serverClusterMeasurement.getAcPowerDivisor(Long.MAX_VALUE);
multiplier = serverClusterMeasurement.getAcPowerMultiplier(Long.MAX_VALUE);
ZclAttribute divAttribute = serverClusterMeasurement
.getAttribute(ZclElectricalMeasurementCluster.ATTR_ACPOWERDIVISOR);
ZclAttribute mulAttribute = serverClusterMeasurement
.getAttribute(ZclElectricalMeasurementCluster.ATTR_ACPOWERMULTIPLIER);

divisor = (Integer) divAttribute.readValue(Long.MAX_VALUE);
multiplier = (Integer) mulAttribute.readValue(Long.MAX_VALUE);
if (divisor == null || multiplier == null) {
divisor = 1;
multiplier = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import javax.measure.quantity.ElectricCurrent;

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.QuantityType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.converter.ZigBeeBaseChannelConverter;
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -166,8 +166,13 @@ public void attributeUpdated(ZclAttribute attribute, Object val) {
}

private void determineDivisorAndMultiplier(ZclElectricalMeasurementCluster serverClusterMeasurement) {
divisor = serverClusterMeasurement.getAcPowerDivisor(Long.MAX_VALUE);
multiplier = serverClusterMeasurement.getAcPowerMultiplier(Long.MAX_VALUE);
ZclAttribute divAttribute = serverClusterMeasurement
.getAttribute(ZclElectricalMeasurementCluster.ATTR_ACPOWERDIVISOR);
ZclAttribute mulAttribute = serverClusterMeasurement
.getAttribute(ZclElectricalMeasurementCluster.ATTR_ACPOWERMULTIPLIER);

divisor = (Integer) divAttribute.readValue(Long.MAX_VALUE);
multiplier = (Integer) mulAttribute.readValue(Long.MAX_VALUE);
if (divisor == null || multiplier == null) {
divisor = 1;
multiplier = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import javax.measure.quantity.ElectricPotential;

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.QuantityType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.converter.ZigBeeBaseChannelConverter;
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -166,8 +166,13 @@ public void attributeUpdated(ZclAttribute attribute, Object val) {
}

private void determineDivisorAndMultiplier(ZclElectricalMeasurementCluster serverClusterMeasurement) {
divisor = serverClusterMeasurement.getAcPowerDivisor(Long.MAX_VALUE);
multiplier = serverClusterMeasurement.getAcPowerMultiplier(Long.MAX_VALUE);
ZclAttribute divAttribute = serverClusterMeasurement
.getAttribute(ZclElectricalMeasurementCluster.ATTR_ACPOWERDIVISOR);
ZclAttribute mulAttribute = serverClusterMeasurement
.getAttribute(ZclElectricalMeasurementCluster.ATTR_ACPOWERMULTIPLIER);

divisor = (Integer) divAttribute.readValue(Long.MAX_VALUE);
multiplier = (Integer) mulAttribute.readValue(Long.MAX_VALUE);
if (divisor == null || multiplier == null) {
divisor = 1;
multiplier = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,4 @@ private void determineDivisorAndMultiplier(ZclMeteringCluster serverClusterMeasu
divisor = iDiv;
multiplier = iMult;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import java.util.Set;
import java.util.concurrent.ExecutionException;

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.openhab.binding.zigbee.ZigBeeBindingConstants;
import org.openhab.binding.zigbee.converter.ZigBeeBaseChannelConverter;
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -44,6 +44,7 @@ public class ZigBeeConverterRelativeHumidity extends ZigBeeBaseChannelConverter
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterRelativeHumidity.class);

private ZclRelativeHumidityMeasurementCluster cluster;
private ZclAttribute attribute;

@Override
public Set<Integer> getImplementedClientClusters() {
Expand All @@ -67,10 +68,12 @@ public boolean initializeDevice() {
try {
CommandResult bindResponse = bind(serverCluster).get();
if (bindResponse.isSuccess()) {
// Configure reporting - no faster than once per second - no slower than 2 hours.
CommandResult response = serverCluster.setMeasuredValueReporting(1, REPORTING_PERIOD_DEFAULT_MAX, 0.1)
.get();
handleReportingResponse(response, POLLING_PERIOD_DEFAULT, REPORTING_PERIOD_DEFAULT_MAX);
// Configure reporting
ZclAttribute attribute = serverCluster
.getAttribute(ZclRelativeHumidityMeasurementCluster.ATTR_MEASUREDVALUE);
CommandResult reportingResponse = attribute
.setReporting(REPORTING_PERIOD_DEFAULT_MIN, REPORTING_PERIOD_DEFAULT_MAX, 0.1).get();
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, REPORTING_PERIOD_DEFAULT_MAX);
}
} catch (InterruptedException | ExecutionException e) {
logger.error("{}: Exception setting reporting ", endpoint.getIeeeAddress(), e);
Expand All @@ -90,6 +93,12 @@ public boolean initializeConverter(ZigBeeThingHandler thing) {
return false;
}

attribute = cluster.getAttribute(ZclRelativeHumidityMeasurementCluster.ATTR_MEASUREDVALUE);
if (attribute == null) {
logger.error("{}: Error opening device measured value attribute", endpoint.getIeeeAddress());
return false;
}

// Add a listener, then request the status
cluster.addAttributeListener(this);
return true;
Expand All @@ -102,7 +111,7 @@ public void disposeConverter() {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ private void startStopTimer(int delay) {
@Override
public void run() {
logger.debug("{}: IncreaseDecrease Stop timer expired", endpoint.getIeeeAddress());
clusterLevelControlServer.stopWithOnOffCommand();
clusterLevelControlServer.sendCommand(new StopWithOnOffCommand());
lastCommand = null;
updateTimer = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ZigBeeConverterThermostatLocalTemperature extends ZigBeeBaseChannel
private final int INVALID_TEMPERATURE = 0x8000;

private ZclThermostatCluster cluster;
private ZclAttribute attribute;

@Override
public Set<Integer> getImplementedClientClusters() {
Expand All @@ -69,9 +70,9 @@ public boolean initializeDevice() {
CommandResult bindResponse = bind(serverCluster).get();
if (bindResponse.isSuccess()) {
// Configure reporting
CommandResult reportingResponse = serverCluster
.setLocalTemperatureReporting(REPORTING_PERIOD_DEFAULT_MIN, REPORTING_PERIOD_DEFAULT_MAX, 0.1)
.get();
ZclAttribute attribute = serverCluster.getAttribute(ZclThermostatCluster.ATTR_LOCALTEMPERATURE);
CommandResult reportingResponse = attribute
.setReporting(REPORTING_PERIOD_DEFAULT_MIN, REPORTING_PERIOD_DEFAULT_MAX, 0.1).get();
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, REPORTING_PERIOD_DEFAULT_MAX);
} else {
logger.debug("{}: Failed to bind thermostat cluster", endpoint.getIeeeAddress());
Expand All @@ -93,6 +94,12 @@ public boolean initializeConverter(ZigBeeThingHandler thing) {
return false;
}

attribute = cluster.getAttribute(ZclThermostatCluster.ATTR_LOCALTEMPERATURE);
if (attribute == null) {
logger.error("{}: Error opening device thermostat local temperature attribute", endpoint.getIeeeAddress());
return false;
}

// Add a listener, then request the status
cluster.addAttributeListener(this);
return true;
Expand All @@ -105,7 +112,7 @@ public void disposeConverter() {

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

@Override
Expand Down