-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add units to Illuminance and Relative Humidity, fix missing units #765
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,18 @@ | |
package org.openhab.binding.zigbee.internal.converter; | ||
|
||
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; | ||
|
||
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; | ||
|
@@ -43,8 +47,13 @@ | |
public class ZigBeeConverterRelativeHumidity extends ZigBeeBaseChannelConverter implements ZclAttributeListener { | ||
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterRelativeHumidity.class); | ||
|
||
private static BigDecimal CHANGE_DEFAULT = new BigDecimal(50); | ||
private static BigDecimal CHANGE_MIN = new BigDecimal(1); | ||
private static BigDecimal CHANGE_MAX = new BigDecimal(10000); | ||
|
||
private ZclRelativeHumidityMeasurementCluster cluster; | ||
private ZclAttribute attribute; | ||
private ZclReportingConfig configReporting; | ||
|
||
@Override | ||
public Set<Integer> getImplementedClientClusters() { | ||
|
@@ -65,15 +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(ZclRelativeHumidityMeasurementCluster.ATTR_MEASUREDVALUE); | ||
CommandResult reportingResponse = attribute | ||
.setReporting(REPORTING_PERIOD_DEFAULT_MIN, REPORTING_PERIOD_DEFAULT_MAX, 50).get(); | ||
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, REPORTING_PERIOD_DEFAULT_MAX); | ||
CommandResult reportingResponse = attribute.setReporting(reporting.getReportingTimeMin(), | ||
reporting.getReportingTimeMax(), reporting.getReportingChange()).get(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not exactly clear on the lifecycle order—would the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No - it won't - it will use whatever the default is in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming the device does not immediately get reconfigured later with the actual default either (unless the user goes in and changes/saves the channel options)? |
||
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, reporting.getPollingPeriod()); | ||
} | ||
} catch (InterruptedException | ExecutionException e) { | ||
logger.error("{}: Exception setting reporting ", endpoint.getIeeeAddress(), e); | ||
|
@@ -99,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; | ||
|
@@ -109,11 +126,33 @@ 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 Configuration currentConfiguration, | ||
Map<String, Object> updatedParameters) { | ||
if (configReporting.updateConfiguration(currentConfiguration, updatedParameters)) { | ||
try { | ||
ZclAttribute attribute = cluster.getAttribute(ZclRelativeHumidityMeasurementCluster.ATTR_MEASUREDVALUE); | ||
CommandResult reportingResponse; | ||
reportingResponse = attribute.setReporting(configReporting.getReportingTimeMin(), | ||
configReporting.getReportingTimeMax(), configReporting.getReportingChange()).get(); | ||
handleReportingResponse(reportingResponse, configReporting.getPollingPeriod(), | ||
configReporting.getReportingTimeMax()); | ||
} catch (InterruptedException | ExecutionException e) { | ||
logger.debug("{}: Relative humidity measurement exception setting reporting", endpoint.getIeeeAddress(), e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) { | ||
if (endpoint.getInputCluster(ZclRelativeHumidityMeasurementCluster.CLUSTER_ID) == null) { | ||
|
@@ -123,7 +162,7 @@ public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) { | |
|
||
return ChannelBuilder | ||
.create(createChannelUID(thingUID, endpoint, ZigBeeBindingConstants.CHANNEL_NAME_HUMIDITY_VALUE), | ||
ZigBeeBindingConstants.ITEM_TYPE_NUMBER) | ||
ZigBeeBindingConstants.ITEM_TYPE_NUMBER_DIMENSIONLESS) | ||
.withType(ZigBeeBindingConstants.CHANNEL_HUMIDITY_VALUE) | ||
.withLabel(ZigBeeBindingConstants.CHANNEL_LABEL_HUMIDITY_VALUE) | ||
.withProperties(createProperties(endpoint)).build(); | ||
|
@@ -135,7 +174,7 @@ public void attributeUpdated(ZclAttribute attribute, Object val) { | |
if (attribute.getClusterType() == ZclClusterType.RELATIVE_HUMIDITY_MEASUREMENT | ||
&& attribute.getId() == ZclRelativeHumidityMeasurementCluster.ATTR_MEASUREDVALUE) { | ||
Integer value = (Integer) val; | ||
updateChannelState(new DecimalType(BigDecimal.valueOf(value, 2))); | ||
updateChannelState(valueToPercentDimensionless(BigDecimal.valueOf(value, 2))); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming when we dynamically generate channels, e.g. for a generic device without a thing XML definition, we ignore the contents of
channels.xml
completely? Thus without changing the type here we were not actually getting the correct channel type?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - the channels XML file is not ignored. The channel type definitions are still required. When you define a channel (either programatically or in the thing XML file) you have to specify the channel-type, but the channel can also override certain aspects of this. I'm pretty sure that if you try and define a channel that doesn't have a channel type defined, it will error.