Some bugfixes for multiple reports

This commit is contained in:
Ziver Koc 2021-08-28 16:10:58 +02:00
parent 17438db7a2
commit a21ac02333
9 changed files with 21 additions and 15 deletions

View file

@ -26,7 +26,7 @@ public class SensorControllerManager extends HalAbstractControllerManager<HalAbs
/** List of all registered sensors **/
private List<Sensor> registeredSensors = Collections.synchronizedList(new ArrayList<>());
/** List of auto detected sensors **/
/** List of auto-detected sensors **/
private List<Sensor> detectedSensors = Collections.synchronizedList(new ArrayList<>());
@ -122,7 +122,7 @@ public class SensorControllerManager extends HalAbstractControllerManager<HalAbs
}
/**
* Removes all auto detected sensors.
* Removes all auto-detected sensors.
*/
@Override
public void clearDetectedDevices(){

View file

@ -28,15 +28,13 @@ public class SendEventAction implements HalAction {
@Override
public void execute() {
try {
DBConnection db = HalContext.getDB();
if (event != null) {
HalEventData dataObj = (HalEventData) event.getDeviceConfig().getDeviceDataClass().newInstance();
HalEventData dataObj = (HalEventData) event.getDeviceConfig().getDeviceDataClass().getDeclaredConstructor().newInstance();
dataObj.setData(data);
event.setDeviceData(dataObj);
// Send
EventControllerManager.getInstance().send(event);
}
else
} else
logger.warning("Unable to find event with id: "+ event.getId());
} catch (Exception e) {
logger.log(Level.SEVERE, null, e);

View file

@ -47,7 +47,7 @@ public class ConfigEventValueProvider implements Configurator.ConfigValueProvide
@Override
public List<String> getPossibleValues() {
return new ArrayList<String>(events.keySet());
return new ArrayList<>(events.keySet());
}
@Override

View file

@ -318,8 +318,12 @@ public class ZigbeeController implements HalSensorController,
@Override
public void attributeUpdated(ZclAttribute attribute, Object value) {
logger.finer("[Node: " + endpoint.getIeeeAddress() + ", Endpoint: " + endpoint.getEndpointId() + ", Cluster: " + attribute.getCluster().getId() + "] Attribute " + config.getClass().getSimpleName() + " updated: id=" + attribute.getId() + ", attribute_name=" + attribute.getName() + ", value=" + attribute.getLastValue());
for (HalDeviceReportListener deviceListener : deviceListeners) {
deviceListener.reportReceived(config, config.getDeviceData(attribute));
HalDeviceData data = config.getDeviceData(attribute);
if (data != null) {
for (HalDeviceReportListener deviceListener : deviceListeners) {
deviceListener.reportReceived(config, data);
}
}
}
});

View file

@ -56,8 +56,8 @@ public abstract class ZigbeeHalDeviceConfig implements HalDeviceConfig {
public void initialize(ZclCluster cluster) {}
/**
* @param zclAttribute
* @return a HalDeviceData object containing the same value representation as the endpoint.
* @param zclAttribute is the object that should be mapped to a HalDeviceFata object.
* @return a HalDeviceData object containing the same value representation as the endpoint or null if this attribute is not translatable.
*/
public abstract HalDeviceData getDeviceData(ZclAttribute zclAttribute);

View file

@ -18,7 +18,8 @@ public class ZigbeeHumidityConfig extends ZigbeeHalDeviceConfig implements HalSe
@Override
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
if (zclAttribute.getId() == ZclRelativeHumidityMeasurementCluster.ATTR_MEASUREDVALUE)
if (zclAttribute.getCluster().getId() == getZigbeeClusterId() &&
zclAttribute.getId() == ZclRelativeHumidityMeasurementCluster.ATTR_MEASUREDVALUE)
return new HumiditySensorData(
((int) zclAttribute.getLastValue()) / 100.0,
zclAttribute.getLastReportTime().getTimeInMillis());

View file

@ -41,7 +41,8 @@ public class ZigbeeOnOffConfig extends ZigbeeHalEventDeviceConfig implements Hal
@Override
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
if (zclAttribute.getId() == ZclOnOffCluster.ATTR_ONOFF)
if (zclAttribute.getCluster().getId() == getZigbeeClusterId() &&
zclAttribute.getId() == ZclOnOffCluster.ATTR_ONOFF)
return new OnOffEventData(
(boolean) zclAttribute.getLastValue(),
zclAttribute.getLastReportTime().getTimeInMillis());

View file

@ -19,7 +19,8 @@ public class ZigbeePressureConfig extends ZigbeeHalDeviceConfig implements HalSe
@Override
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
if (zclAttribute.getId() == ZclTemperatureMeasurementCluster.ATTR_MAXMEASUREDVALUE)
if (zclAttribute.getCluster().getId() == getZigbeeClusterId() &&
zclAttribute.getId() == ZclTemperatureMeasurementCluster.ATTR_MAXMEASUREDVALUE)
return new PressureSensorData(
(int) zclAttribute.getLastValue(),
zclAttribute.getLastReportTime().getTimeInMillis());

View file

@ -18,7 +18,8 @@ public class ZigbeeTemperatureConfig extends ZigbeeHalDeviceConfig implements Ha
@Override
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
if (zclAttribute.getId() == ZclTemperatureMeasurementCluster.ATTR_MEASUREDVALUE)
if (zclAttribute.getCluster().getId() == getZigbeeClusterId() &&
zclAttribute.getId() == ZclTemperatureMeasurementCluster.ATTR_MEASUREDVALUE)
return new TemperatureSensorData(
((int) zclAttribute.getLastValue()) / 100.0,
zclAttribute.getLastReportTime().getTimeInMillis());