Hal now properly detects Zigbee sensors
This commit is contained in:
parent
902d87a9c5
commit
52273e1ebe
6 changed files with 38 additions and 29 deletions
|
|
@ -224,6 +224,10 @@ public class HalZigbeeController implements HalSensorController,
|
|||
logger.fine("[Node: " + node.getIeeeAddress() + "]: Node has been registered: " +
|
||||
"Manufacturer=" + node.getNodeDescriptor().getManufacturerCode() +
|
||||
", Type=" + node.getNodeDescriptor().getLogicalType());
|
||||
|
||||
for (ZigBeeEndpoint endpoint : node.getEndpoints()) {
|
||||
deviceAdded(endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -250,10 +254,29 @@ public class HalZigbeeController implements HalSensorController,
|
|||
logger.fine("[Node: " + endpoint.getIeeeAddress() + ", Endpoint: " + endpoint.getEndpointId() + "]: Received a Zigbee endpoint update: " + endpoint);
|
||||
|
||||
for (int inputClusterId : endpoint.getInputClusterIds()) {
|
||||
ZclCluster cluster = endpoint.getInputCluster(inputClusterId);
|
||||
ZigbeeHalDeviceConfig config = createDeviceConfig(inputClusterId);
|
||||
|
||||
if (config != null) {
|
||||
registerCluster(endpoint, config);
|
||||
if (cluster != null && config != null) {
|
||||
config.setZigbeeNodeAddress(endpoint.getIeeeAddress());
|
||||
|
||||
cluster.addAttributeListener(new ZclAttributeListener() {
|
||||
@Override
|
||||
public void attributeUpdated(ZclAttribute attribute, Object value) {
|
||||
if (attribute.getId() != 0) // Only report on Measured Value attribute updates
|
||||
return;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// // TODO: Notify listener that a device is online
|
||||
for (HalDeviceReportListener deviceListener : deviceListeners) {
|
||||
deviceListener.reportReceived(config, null);
|
||||
}
|
||||
} else {
|
||||
logger.finest("[Node: " + endpoint.getIeeeAddress() + ", Endpoint: " + endpoint.getEndpointId() + "] Cluster ID '" + inputClusterId + "' is not supported.");
|
||||
}
|
||||
|
|
@ -271,27 +294,6 @@ public class HalZigbeeController implements HalSensorController,
|
|||
return null;
|
||||
}
|
||||
|
||||
private void registerCluster(final ZigBeeEndpoint endpoint, ZigbeeHalDeviceConfig config) {
|
||||
final ZclCluster cluster = endpoint.getInputCluster(config.getZigbeeClusterId());
|
||||
if (cluster != null) {
|
||||
config.setZigbeeNodeAddress(endpoint.getIeeeAddress());
|
||||
|
||||
cluster.addAttributeListener(new ZclAttributeListener() {
|
||||
@Override
|
||||
public void attributeUpdated(ZclAttribute attribute, Object value) {
|
||||
for (HalDeviceReportListener deviceListener : deviceListeners) {
|
||||
logger.finer("[Node: " + endpoint.getIeeeAddress() + ", Endpoint: " + endpoint.getEndpointId() + ", Cluster: " + attribute.getCluster().getId() + "] Attribute updated: attribute_name=" + attribute.getName() + ", value=" + attribute.getLastValue());
|
||||
deviceListener.reportReceived(config, config.getDeviceData(attribute));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// // TODO: Notify listener that a device is online
|
||||
for (HalDeviceReportListener deviceListener : deviceListeners) {
|
||||
deviceListener.reportReceived(config, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deviceRemoved(ZigBeeEndpoint endpoint) {
|
||||
|
|
|
|||
|
|
@ -59,4 +59,10 @@ public abstract class ZigbeeHalDeviceConfig implements HalDeviceConfig {
|
|||
return zigbeeNodeAddress.equals(that.zigbeeNodeAddress) &&
|
||||
getZigbeeClusterId() == that.getZigbeeClusterId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Address: " + getZigbeeNodeAddress() + "; Cluster ID: " + getZigbeeClusterId();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.zsmartsystems.zigbee.zcl.clusters.ZclRelativeHumidityMeasurementClust
|
|||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.struct.devicedata.HumiditySensorData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
|
||||
/**
|
||||
* A device configuration for a specific endpoint on a Zigbee device.
|
||||
|
|
@ -17,7 +18,7 @@ public class ZigbeeHumidityConfig extends ZigbeeHalDeviceConfig implements HalSe
|
|||
|
||||
@Override
|
||||
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
|
||||
return null;
|
||||
return new HumiditySensorData(((int) zclAttribute.getLastValue()) / 100.0, zclAttribute.getLastReportTime().getTimeInMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.zsmartsystems.zigbee.zcl.ZclAttribute;
|
|||
import com.zsmartsystems.zigbee.zcl.clusters.ZclTemperatureMeasurementCluster;
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.struct.devicedata.HumiditySensorData;
|
||||
import se.hal.struct.devicedata.PressureSensorData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
|
||||
/**
|
||||
|
|
@ -17,7 +19,7 @@ public class ZigbeePressureConfig extends ZigbeeHalDeviceConfig implements HalSe
|
|||
|
||||
@Override
|
||||
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
|
||||
return null;
|
||||
return new PressureSensorData(((int) zclAttribute.getLastValue()), zclAttribute.getLastReportTime().getTimeInMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -43,6 +45,4 @@ public class ZigbeePressureConfig extends ZigbeeHalDeviceConfig implements HalSe
|
|||
public Class<? extends HalDeviceData> getDeviceDataClass() {
|
||||
return TemperatureSensorData.class;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class ZigbeeTemperatureConfig extends ZigbeeHalDeviceConfig implements Ha
|
|||
|
||||
@Override
|
||||
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
|
||||
return null;
|
||||
return new TemperatureSensorData(((int) zclAttribute.getLastValue()) / 100.0, zclAttribute.getLastReportTime().getTimeInMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue