Renamed some DeviceData classes, added additional data classes also and better handling in zigbee
This commit is contained in:
parent
dc200294be
commit
3edea58f8c
18 changed files with 275 additions and 45 deletions
|
|
@ -32,7 +32,6 @@ import se.hal.intf.HalDeviceConfig;
|
|||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
|
@ -71,9 +70,9 @@ public class OnOffTrait extends DeviceTrait {
|
|||
if ("action.devices.commands.OnOff".equals(execution.command)) {
|
||||
OnOffEventData eventData = new OnOffEventData();
|
||||
if ((boolean) execution.getParams().get("on"))
|
||||
eventData.turnOn();
|
||||
eventData.setOn();
|
||||
else
|
||||
eventData.turnOff();
|
||||
eventData.setOff();
|
||||
|
||||
EventControllerManager.getInstance().send((Event) device, eventData);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import se.hal.plugin.tellstick.TellstickDevice;
|
|||
import se.hal.plugin.tellstick.TellstickSerialComm;
|
||||
import se.hal.plugin.tellstick.protocol.Oregon0x1A2DProtocol;
|
||||
import se.hal.struct.devicedata.HumiditySensorData;
|
||||
import se.hal.struct.devicedata.LightSensorData;
|
||||
import se.hal.struct.devicedata.IlluminanceSensorData;
|
||||
import se.hal.struct.devicedata.PowerConsumptionSensorData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import zutil.log.LogUtil;
|
||||
|
|
@ -78,7 +78,7 @@ public class Oregon0x1A2D implements TellstickDevice, HalSensorConfig {
|
|||
case HUMIDITY:
|
||||
return HumiditySensorData.class;
|
||||
case LIGHT:
|
||||
return LightSensorData.class;
|
||||
return IlluminanceSensorData.class;
|
||||
case POWER:
|
||||
return PowerConsumptionSensorData.class;
|
||||
case TEMPERATURE:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import se.hal.plugin.tellstick.TellstickSerialComm;
|
|||
import se.hal.plugin.tellstick.device.Oregon0x1A2D;
|
||||
import se.hal.plugin.tellstick.device.Oregon0x1A2D.OregonSensorType;
|
||||
import se.hal.struct.devicedata.HumiditySensorData;
|
||||
import se.hal.struct.devicedata.LightSensorData;
|
||||
import se.hal.struct.devicedata.IlluminanceSensorData;
|
||||
import se.hal.struct.devicedata.PowerConsumptionSensorData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import zutil.converter.Converter;
|
||||
|
|
@ -90,7 +90,7 @@ public class Oregon0x1A2DProtocol extends TellstickProtocol {
|
|||
humidityFound = true;
|
||||
break;
|
||||
case LIGHT:
|
||||
dataObj = new LightSensorData(temperature, timestamp);
|
||||
dataObj = new IlluminanceSensorData(temperature, timestamp);
|
||||
temperatureFound = true;
|
||||
break;
|
||||
case TEMPERATURE:
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class TelstickSerialCommNexaOnOffTest {
|
|||
System.out.println("Up and Running");
|
||||
while (true) {
|
||||
Thread.sleep(2000);
|
||||
nexaData.turnOn();
|
||||
nexaData.setOn();
|
||||
nexaDevice.setUnit(0);
|
||||
comm.send(nexaDevice, nexaData);
|
||||
Thread.sleep(2000);
|
||||
|
|
@ -38,7 +38,7 @@ public class TelstickSerialCommNexaOnOffTest {
|
|||
Thread.sleep(2000);
|
||||
|
||||
|
||||
nexaData.turnOff();
|
||||
nexaData.setOff();
|
||||
nexaDevice.setUnit(0);
|
||||
comm.send(nexaDevice, nexaData);
|
||||
Thread.sleep(2000);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@
|
|||
<!-- NODE -->
|
||||
|
||||
<div class="panel-heading">
|
||||
<a href="#a" data-toggle="collapse" data-target="#node-{{.getIeeeAddress()}}">Node: {{.getIeeeAddress()}}</a>
|
||||
<a href="#a" data-toggle="collapse" data-target="#node-{{.getIeeeAddress()}}">
|
||||
Node: {{.getIeeeAddress()}}
|
||||
</a>
|
||||
</div>
|
||||
<div id="node-{{.getIeeeAddress()}}" class="panel-body collapse">
|
||||
<div class="col-md-6">
|
||||
|
|
@ -100,7 +102,9 @@
|
|||
{{#.getEndpoints()}}
|
||||
<div class="panel panel-default drop-shadow">
|
||||
<div class="panel-heading">
|
||||
<a href="#a" data-toggle="collapse" data-target="#node-{{.getIeeeAddress()}}-endpoint-{{.getDeviceId()}}">Endpoint: {{.getDeviceId()}}</a>
|
||||
<a href="#a" data-toggle="collapse" data-target="#node-{{.getIeeeAddress()}}-endpoint-{{.getDeviceId()}}">
|
||||
Endpoint: {{.getDeviceId()}}
|
||||
</a>
|
||||
</div>
|
||||
<div id="node-{{.getIeeeAddress()}}-endpoint-{{.getDeviceId()}}" class="panel-body collapse">
|
||||
|
||||
|
|
@ -109,7 +113,9 @@
|
|||
{{#.inputClusters.values()}}
|
||||
<div class="panel panel-default drop-shadow">
|
||||
<div class="panel-heading">
|
||||
<a href="#a" data-toggle="collapse" data-target="#node-{{.getZigBeeAddress().getAddress()}}-endpoint-{{.getZigBeeAddress().getEndpoint()}}-in-cluster-{{.getClusterId()}}">Cluster: {{.getClusterId()}}</a>
|
||||
<a href="#a" data-toggle="collapse" data-target="#node-{{.getZigBeeAddress().getAddress()}}-endpoint-{{.getZigBeeAddress().getEndpoint()}}-in-cluster-{{.getClusterId()}}">
|
||||
Cluster: {{.CLUSTER_NAME}} ({{.getClusterId()}})
|
||||
</a>
|
||||
</div>
|
||||
<div id="node-{{.getZigBeeAddress().getAddress()}}-endpoint-{{.getZigBeeAddress().getEndpoint()}}-in-cluster-{{.getClusterId()}}" class="panel-body collapse">
|
||||
<table class="table table-hover table-condensed">
|
||||
|
|
@ -137,7 +143,9 @@
|
|||
{{#.outputClusters.values()}}
|
||||
<div class="panel panel-default drop-shadow">
|
||||
<div class="panel-heading">
|
||||
<a data-toggle="collapse" data-target="#node-{{.getZigBeeAddress().getAddress()}}-endpoint-{{.getZigBeeAddress().getEndpoint()}}-out-cluster-{{.getClusterId()}}">Cluster: {{.getClusterId()}}</a>
|
||||
<a data-toggle="collapse" data-target="#node-{{.getZigBeeAddress().getAddress()}}-endpoint-{{.getZigBeeAddress().getEndpoint()}}-out-cluster-{{.getClusterId()}}">
|
||||
Cluster: {{.CLUSTER_NAME}} ({{.getClusterId()}})
|
||||
</a>
|
||||
</div>
|
||||
<div id="node-{{.getZigBeeAddress().getAddress()}}-endpoint-{{.getZigBeeAddress().getEndpoint()}}-out-cluster-{{.getClusterId()}}" class="panel-body collapse">
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,12 @@ import com.zsmartsystems.zigbee.zcl.ZclAttributeListener;
|
|||
import com.zsmartsystems.zigbee.zcl.ZclCluster;
|
||||
import com.zsmartsystems.zigbee.zcl.clusters.*;
|
||||
import com.zsmartsystems.zigbee.zdo.field.NodeDescriptor;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.plugin.zigbee.db.ZigBeeHalDataStore;
|
||||
import se.hal.plugin.zigbee.device.*;
|
||||
|
||||
import zutil.Timer;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
|
|
@ -291,7 +293,7 @@ public class ZigbeeController implements HalSensorController,
|
|||
|
||||
for (int inputClusterId : endpoint.getInputClusterIds()) {
|
||||
ZclCluster cluster = endpoint.getInputCluster(inputClusterId);
|
||||
ZigbeeHalDeviceConfig config = createDeviceConfig(inputClusterId);
|
||||
ZigbeeHalDeviceConfig config = ZigbeeHalDeviceFactory.getDeviceConfig(inputClusterId);
|
||||
|
||||
// Read basic attributes
|
||||
if (cluster instanceof ZclBasicCluster) {
|
||||
|
|
@ -338,18 +340,6 @@ public class ZigbeeController implements HalSensorController,
|
|||
}
|
||||
}
|
||||
|
||||
private ZigbeeHalDeviceConfig createDeviceConfig(int clusterId) {
|
||||
switch (clusterId) {
|
||||
case ZclRelativeHumidityMeasurementCluster.CLUSTER_ID: return new ZigbeeHumidityConfig();
|
||||
case ZclOnOffCluster.CLUSTER_ID: return new ZigbeeOnOffConfig();
|
||||
case ZclPressureMeasurementCluster.CLUSTER_ID: return new ZigbeePressureConfig();
|
||||
case ZclTemperatureMeasurementCluster.CLUSTER_ID: return new ZigbeeTemperatureConfig();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deviceRemoved(ZigBeeEndpoint endpoint) {
|
||||
logger.fine("[Node: " + endpoint.getIeeeAddress() + ", Endpoint: " + endpoint.getEndpointId() + "]: Endpoint removed: " + endpoint);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package se.hal.plugin.zigbee.device;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A factory class for getting new instances of {@link ZigbeeHalDeviceConfig} objects.
|
||||
*/
|
||||
public class ZigbeeHalDeviceFactory {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
private static final HashMap<Integer, Class<? extends ZigbeeHalDeviceConfig>> clusterDeviceMap = new HashMap<>();
|
||||
static {
|
||||
clusterDeviceMap.put(new ZigbeeHumidityConfig().getZigbeeClusterId(), ZigbeeHumidityConfig.class);
|
||||
clusterDeviceMap.put(new ZigbeeIlluminanceConfig().getZigbeeClusterId(), ZigbeeIlluminanceConfig.class);
|
||||
clusterDeviceMap.put(new ZigbeeOccupancyConfig().getZigbeeClusterId(), ZigbeeOccupancyConfig.class);
|
||||
clusterDeviceMap.put(new ZigbeeOnOffConfig().getZigbeeClusterId(), ZigbeeOnOffConfig.class);
|
||||
clusterDeviceMap.put(new ZigbeePressureConfig().getZigbeeClusterId(), ZigbeePressureConfig.class);
|
||||
clusterDeviceMap.put(new ZigbeeTemperatureConfig().getZigbeeClusterId(), ZigbeeTemperatureConfig.class);
|
||||
}
|
||||
|
||||
|
||||
public static ZigbeeHalDeviceConfig getDeviceConfig(int cluster) {
|
||||
try {
|
||||
Class<? extends ZigbeeHalDeviceConfig> clazz = clusterDeviceMap.get(cluster);
|
||||
|
||||
if (clazz != null) {
|
||||
return clazz.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
logger.log(Level.SEVERE, "Unable to instantiate ZigbeeHalDeviceConfig: " + clusterDeviceMap.get(cluster), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -55,6 +55,8 @@ public abstract class ZigbeeHalEventDeviceConfig extends ZigbeeHalDeviceConfig {
|
|||
* @param data is the Hal event data value that should be converted.
|
||||
* @return a new Zigbee command object or null if no equal representation can be created based on the data.
|
||||
*/
|
||||
protected abstract ZclCommand getZigbeeCommandObject(HalEventData data);
|
||||
protected ZclCommand getZigbeeCommandObject(HalEventData data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package se.hal.plugin.zigbee.device;
|
||||
|
||||
import com.zsmartsystems.zigbee.zcl.ZclAttribute;
|
||||
import com.zsmartsystems.zigbee.zcl.clusters.ZclIlluminanceMeasurementCluster;
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.struct.devicedata.IlluminanceSensorData;
|
||||
|
||||
/**
|
||||
* A device configuration for a specific endpoint on a Zigbee device.
|
||||
*/
|
||||
public class ZigbeeIlluminanceConfig extends ZigbeeHalDeviceConfig implements HalSensorConfig {
|
||||
|
||||
// --------------------------
|
||||
// Zigbee Methods
|
||||
// --------------------------
|
||||
|
||||
@Override
|
||||
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
|
||||
if (zclAttribute.getCluster().getId() == getZigbeeClusterId() &&
|
||||
zclAttribute.getId() == ZclIlluminanceMeasurementCluster.ATTR_MEASUREDVALUE)
|
||||
return new IlluminanceSensorData(
|
||||
(int) zclAttribute.getLastValue(),
|
||||
zclAttribute.getLastReportTime().getTimeInMillis());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZigbeeClusterId() {
|
||||
return ZclIlluminanceMeasurementCluster.CLUSTER_ID;
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Hal Methods
|
||||
// --------------------------
|
||||
|
||||
@Override
|
||||
public AggregationMethod getAggregationMethod() {
|
||||
return AggregationMethod.AVERAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalDeviceData> getDeviceDataClass() {
|
||||
return IlluminanceSensorData.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package se.hal.plugin.zigbee.device;
|
||||
|
||||
import com.zsmartsystems.zigbee.zcl.ZclAttribute;
|
||||
import com.zsmartsystems.zigbee.zcl.ZclCluster;
|
||||
import com.zsmartsystems.zigbee.zcl.clusters.ZclOccupancySensingCluster;
|
||||
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.struct.devicedata.OccupancyEventData;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A device configuration for a specific endpoint on a Zigbee device.
|
||||
*/
|
||||
public class ZigbeeOccupancyConfig extends ZigbeeHalEventDeviceConfig implements HalEventConfig {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
// --------------------------
|
||||
// Zigbee Methods
|
||||
// --------------------------
|
||||
|
||||
@Override
|
||||
public void initialize(ZclCluster cluster) {
|
||||
if (! (cluster instanceof ZclOccupancySensingCluster))
|
||||
return;
|
||||
|
||||
try {
|
||||
ZclAttribute attribute = cluster.getAttribute(ZclOccupancySensingCluster.ATTR_OCCUPANCY);
|
||||
attribute.setReporting(1, 900).get();
|
||||
attribute.readValue(60);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.WARNING, "Was unable to initialize cluster reporting rate.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
|
||||
if (zclAttribute.getCluster().getId() == getZigbeeClusterId() &&
|
||||
zclAttribute.getId() == ZclOccupancySensingCluster.ATTR_OCCUPANCY)
|
||||
return new OccupancyEventData(
|
||||
(boolean) zclAttribute.getLastValue(),
|
||||
zclAttribute.getLastReportTime().getTimeInMillis());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZigbeeClusterId() {
|
||||
return ZclOccupancySensingCluster.CLUSTER_ID;
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// Hal Methods
|
||||
// --------------------------
|
||||
|
||||
@Override
|
||||
public Class<? extends HalDeviceData> getDeviceDataClass() {
|
||||
return OccupancyEventData.class;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ public class ZigbeePressureConfig extends ZigbeeHalDeviceConfig implements HalSe
|
|||
@Override
|
||||
public HalDeviceData getDeviceData(ZclAttribute zclAttribute) {
|
||||
if (zclAttribute.getCluster().getId() == getZigbeeClusterId() &&
|
||||
zclAttribute.getId() == ZclTemperatureMeasurementCluster.ATTR_MAXMEASUREDVALUE)
|
||||
zclAttribute.getId() == ZclTemperatureMeasurementCluster.ATTR_MEASUREDVALUE)
|
||||
return new PressureSensorData(
|
||||
(int) zclAttribute.getLastValue(),
|
||||
zclAttribute.getLastReportTime().getTimeInMillis());
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
{"se.hal.intf.HalEventConfig": "se.hal.plugin.zigbee.device.ZigbeeOnOffConfig"},
|
||||
{"se.hal.intf.HalSensorConfig": "se.hal.plugin.zigbee.device.ZigbeeHumidityConfig"},
|
||||
{"se.hal.intf.HalSensorConfig": "se.hal.plugin.zigbee.device.ZigbeeIlluminanceConfig"},
|
||||
{"se.hal.intf.HalEventConfig": "se.hal.plugin.zigbee.device.ZigbeeOccupancyConfig"},
|
||||
{"se.hal.intf.HalSensorConfig": "se.hal.plugin.zigbee.device.ZigbeePressureConfig"},
|
||||
{"se.hal.intf.HalSensorConfig": "se.hal.plugin.zigbee.device.ZigbeeTemperatureConfig"},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue