Moved find device to its own utility method, and added a specific equals method and reworked some test.
This commit is contained in:
parent
7e8938c38c
commit
c7e286f51e
166 changed files with 618 additions and 374 deletions
|
|
@ -1,11 +1,7 @@
|
|||
package se.hal.plugin.dummy;
|
||||
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.HumiditySensorData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
|
||||
|
||||
public class DummyHumiditySensor implements DummyDevice, HalSensorConfig {
|
||||
|
|
@ -40,4 +36,8 @@ public class DummyHumiditySensor implements DummyDevice, HalSensorConfig {
|
|||
return HumiditySensorData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,4 +24,9 @@ public class DummySwitchEvent implements DummyDevice, HalEventConfig {
|
|||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
package se.hal.plugin.dummy;
|
||||
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
|
||||
|
||||
|
|
@ -39,4 +36,8 @@ public class DummyTemperatureSensor implements DummyDevice, HalSensorConfig {
|
|||
return TemperatureSensorData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.equals(obj);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
|
||||
package se.hal.plugin.mqtt.device;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventData;
|
||||
|
|
@ -79,4 +80,11 @@ public class HalMqttDeviceConfig implements HalEventConfig {
|
|||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return HalMqttDeviceData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof HalMqttDeviceConfig)
|
||||
return topic.equals(((HalMqttDeviceConfig) obj).topic);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package se.hal.plugin.netscan;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventData;
|
||||
|
|
@ -23,16 +24,6 @@ public class NetworkDevice implements HalEventConfig {
|
|||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "Host: "+ host;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if (obj instanceof NetworkDevice)
|
||||
return host != null && host.equals(((NetworkDevice) obj).host);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
|
|
@ -42,4 +33,16 @@ public class NetworkDevice implements HalEventConfig {
|
|||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if (obj instanceof NetworkDevice)
|
||||
return host != null && host.equals(((NetworkDevice) obj).host);
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return "Host: "+ host;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
|
||||
package se.hal.plugin.nutups;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
|
|
@ -86,17 +87,6 @@ public class NutUpsDevice implements HalSensorConfig{
|
|||
return 60*1000; // 1 min
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if (obj instanceof NutUpsDevice)
|
||||
return upsId != null && upsId.equals(((NutUpsDevice)obj).upsId);
|
||||
return false;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return "upsId: "+ upsId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregationMethod getAggregationMethod() {
|
||||
return AggregationMethod.SUM;
|
||||
|
|
@ -109,4 +99,16 @@ public class NutUpsDevice implements HalSensorConfig{
|
|||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return PowerConsumptionSensorData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if (obj instanceof NutUpsDevice)
|
||||
return upsId != null && upsId.equals(((NutUpsDevice)obj).upsId);
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return "upsId: "+ upsId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
package se.hal.plugin.nvr.rtsp;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.plugin.nvr.intf.HalCameraController;
|
||||
import se.hal.plugin.nvr.intf.HalCameraConfig;
|
||||
|
|
@ -53,4 +54,11 @@ public class RTSPCameraConfig implements HalCameraConfig {
|
|||
public Class<? extends HalDeviceData> getDeviceDataClass() {
|
||||
return null; // TODO:
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof RTSPCameraConfig)
|
||||
return rtspUrl.equals(((RTSPCameraConfig) obj).rtspUrl);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package se.hal.plugin.raspberry;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package se.hal.plugin.raspberry;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
|
|
@ -12,13 +13,17 @@ public class RPiTemperatureSensor implements HalSensorConfig {
|
|||
private String w1Address;
|
||||
|
||||
|
||||
|
||||
public RPiTemperatureSensor() { }
|
||||
public RPiTemperatureSensor(String w1Address) {
|
||||
this.w1Address = w1Address;
|
||||
}
|
||||
|
||||
|
||||
public String get1WAddress() {
|
||||
return w1Address;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getDataInterval() {
|
||||
return 10*60*1000; // 10 min
|
||||
|
|
@ -45,9 +50,4 @@ public class RPiTemperatureSensor implements HalSensorConfig {
|
|||
return this.get1WAddress().equals(((RPiTemperatureSensor) obj).w1Address);
|
||||
return false;
|
||||
}
|
||||
|
||||
public String get1WAddress() {
|
||||
return w1Address;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package se.hal.plugin.tellstick;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
|
||||
/**
|
||||
* This interface represents a device configuration and links it to a protocol.
|
||||
*
|
||||
* Created by Ziver on 2016-08-18.
|
||||
*/
|
||||
public interface TellstickDevice {
|
||||
|
||||
public interface TellstickDevice extends HalDeviceConfig {
|
||||
|
||||
String getProtocolName(); // TODO: could be implemented in a better way
|
||||
String getModelName(); // TODO: could be implemented in a better way
|
||||
|
|
|
|||
|
|
@ -37,21 +37,25 @@ public abstract class TellstickProtocol {
|
|||
private final String model;
|
||||
|
||||
|
||||
public TellstickProtocol(String protocol, String model){
|
||||
public TellstickProtocol(String protocol, String model) {
|
||||
this.protocol = protocol;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
|
||||
public String getProtocolName(){
|
||||
public String getProtocolName() {
|
||||
return protocol;
|
||||
}
|
||||
public String getModelName(){
|
||||
|
||||
public String getModelName() {
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
public TellstickCmd encode(HalEventConfig deviceConfig, HalEventData deviceData){ return null; }
|
||||
public TellstickCmd encode(HalEventConfig deviceConfig, HalEventData deviceData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract List<TellstickDecodedEntry> decode(byte[] data);
|
||||
|
||||
|
||||
|
|
@ -59,15 +63,16 @@ public abstract class TellstickProtocol {
|
|||
private TellstickDevice device;
|
||||
private HalDeviceData data;
|
||||
|
||||
public TellstickDecodedEntry(TellstickDevice device, HalDeviceData data){
|
||||
public TellstickDecodedEntry(TellstickDevice device, HalDeviceData data) {
|
||||
this.device = device;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public TellstickDevice getDevice(){
|
||||
public TellstickDevice getDevice() {
|
||||
return device;
|
||||
}
|
||||
public HalDeviceData getData(){
|
||||
|
||||
public HalDeviceData getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,19 +57,15 @@ public class TellstickSerialComm implements Runnable,
|
|||
private SerialPort serial;
|
||||
private InputStream in;
|
||||
private OutputStream out;
|
||||
private TimedHashSet<String> set; // To check for duplicate transmissions
|
||||
private TimedHashSet<String> receivedTransmissionSet = new TimedHashSet<>(TRANSMISSION_UNIQUENESS_TTL); // To check for duplicate transmissions
|
||||
|
||||
protected TellstickParser parser;
|
||||
protected TellstickParser parser = new TellstickParser();
|
||||
|
||||
private HalDeviceReportListener deviceListener;
|
||||
private List<TellstickDevice> registeredDevices;
|
||||
private List<HalDeviceConfig> registeredDevices = Collections.synchronizedList(new ArrayList<HalDeviceConfig>());
|
||||
|
||||
|
||||
public TellstickSerialComm() {
|
||||
set = new TimedHashSet<>(TRANSMISSION_UNIQUENESS_TTL);
|
||||
parser = new TellstickParser();
|
||||
registeredDevices = Collections.synchronizedList(new ArrayList<TellstickDevice>());
|
||||
}
|
||||
public TellstickSerialComm() {}
|
||||
|
||||
// --------------------------
|
||||
// Lifecycle methods
|
||||
|
|
@ -79,6 +75,7 @@ public class TellstickSerialComm implements Runnable,
|
|||
public boolean isAvailable() {
|
||||
return HalContext.containsProperty(CONFIG_TELLSTICK_COM_PORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() throws Exception {
|
||||
initialize(HalContext.getStringProperty(CONFIG_TELLSTICK_COM_PORT));
|
||||
|
|
@ -163,14 +160,16 @@ public class TellstickSerialComm implements Runnable,
|
|||
entry.getData().setTimestamp(System.currentTimeMillis());
|
||||
|
||||
boolean registered = registeredDevices.contains(entry.getDevice());
|
||||
if (registered && !set.contains(data) || // check for duplicates transmissions of registered devices
|
||||
!registered && set.contains(data)) { // required duplicate transmissions before reporting unregistered devices
|
||||
if (registered && !receivedTransmissionSet.contains(data) || // check for duplicates transmissions of registered devices
|
||||
!registered && receivedTransmissionSet.contains(data)) { // required duplicate transmissions before reporting unregistered devices
|
||||
|
||||
//Check for registered device that are in the same group
|
||||
// Check for registered device that are in the same group
|
||||
if (entry.getDevice() instanceof TellstickDeviceGroup) {
|
||||
TellstickDeviceGroup groupProtocol = (TellstickDeviceGroup) entry.getDevice();
|
||||
|
||||
for (int i = 0; i < registeredDevices.size(); ++i) { // Don't use foreach for concurrency reasons
|
||||
TellstickDevice childDevice = registeredDevices.get(i);
|
||||
HalDeviceConfig childDevice = registeredDevices.get(i);
|
||||
|
||||
if (childDevice instanceof TellstickDeviceGroup &&
|
||||
groupProtocol.equalsGroup((TellstickDeviceGroup)childDevice) &&
|
||||
!entry.getDevice().equals(childDevice)) {
|
||||
|
|
@ -182,11 +181,12 @@ public class TellstickSerialComm implements Runnable,
|
|||
reportEvent(entry.getDevice(), entry.getData());
|
||||
}
|
||||
}
|
||||
set.add(data);
|
||||
|
||||
receivedTransmissionSet.add(data);
|
||||
}
|
||||
private void reportEvent(TellstickDevice tellstickDevice, HalDeviceData deviceData){
|
||||
private void reportEvent(HalDeviceConfig tellstickDevice, HalDeviceData deviceData) {
|
||||
if (deviceListener != null)
|
||||
deviceListener.reportReceived((HalDeviceConfig) tellstickDevice, deviceData);
|
||||
deviceListener.reportReceived(tellstickDevice, deviceData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -224,14 +224,14 @@ public class TellstickSerialComm implements Runnable,
|
|||
@Override
|
||||
public void register(HalDeviceConfig deviceConfig) {
|
||||
if(deviceConfig instanceof TellstickDevice)
|
||||
registeredDevices.add((TellstickDevice) deviceConfig);
|
||||
registeredDevices.add(deviceConfig);
|
||||
else throw new IllegalArgumentException(
|
||||
"Device config is not an instance of " + TellstickDevice.class + ": " + deviceConfig.getClass());
|
||||
}
|
||||
|
||||
public <T> List<T> getRegisteredDevices(Class<T> clazz){
|
||||
ArrayList<T> list = new ArrayList<>();
|
||||
for (TellstickDevice device : registeredDevices){
|
||||
for (HalDeviceConfig device : registeredDevices){
|
||||
if (clazz.isAssignableFrom(device.getClass()))
|
||||
list.add((T) device);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
package se.hal.plugin.tellstick.device;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventData;
|
||||
|
|
@ -35,7 +36,7 @@ import zutil.ui.Configurator;
|
|||
/**
|
||||
* Created by Ziver on 2015-02-18.
|
||||
*/
|
||||
public class NexaSelfLearning implements HalEventConfig,TellstickDevice,TellstickDeviceGroup {
|
||||
public class NexaSelfLearning implements TellstickDevice, HalEventConfig, TellstickDeviceGroup {
|
||||
|
||||
@Configurator.Configurable("House code")
|
||||
private int house = 0;
|
||||
|
|
@ -55,7 +56,6 @@ public class NexaSelfLearning implements HalEventConfig,TellstickDevice,Tellstic
|
|||
}
|
||||
|
||||
|
||||
|
||||
public int getHouse() {
|
||||
return house;
|
||||
}
|
||||
|
|
@ -76,11 +76,18 @@ public class NexaSelfLearning implements HalEventConfig,TellstickDevice,Tellstic
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getProtocolName() { return NexaSelfLearningProtocol.PROTOCOL; }
|
||||
@Override
|
||||
public String getModelName() { return NexaSelfLearningProtocol.MODEL; }
|
||||
|
||||
public String toString(){
|
||||
return "house:"+house+
|
||||
", group:"+group+
|
||||
", unit:"+unit;
|
||||
@Override
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return TellstickSerialComm.class;
|
||||
}
|
||||
@Override
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -98,19 +105,10 @@ public class NexaSelfLearning implements HalEventConfig,TellstickDevice,Tellstic
|
|||
(((NexaSelfLearning) obj).group || group );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return TellstickSerialComm.class;
|
||||
public String toString(){
|
||||
return "house:" + house +
|
||||
", group:" + group +
|
||||
", unit:" + unit;
|
||||
}
|
||||
@Override
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName() { return NexaSelfLearningProtocol.PROTOCOL; }
|
||||
@Override
|
||||
public String getModelName() { return NexaSelfLearningProtocol.MODEL; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
package se.hal.plugin.tellstick.device;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventData;
|
||||
|
|
@ -34,7 +35,7 @@ import zutil.ui.Configurator;
|
|||
/**
|
||||
* Created by Ziver on 2015-02-18.
|
||||
*/
|
||||
public class NexaSelfLearningDimmer implements HalEventConfig,TellstickDevice {
|
||||
public class NexaSelfLearningDimmer implements TellstickDevice, HalEventConfig {
|
||||
|
||||
@Configurator.Configurable("House code")
|
||||
private int house = 0;
|
||||
|
|
@ -50,7 +51,6 @@ public class NexaSelfLearningDimmer implements HalEventConfig,TellstickDevice {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public int getHouse() {
|
||||
return house;
|
||||
}
|
||||
|
|
@ -65,19 +65,10 @@ public class NexaSelfLearningDimmer implements HalEventConfig,TellstickDevice {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public String toString(){
|
||||
return "house:"+house+
|
||||
", unit:"+unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof NexaSelfLearningDimmer)
|
||||
return ((NexaSelfLearningDimmer) obj).house == house &&
|
||||
((NexaSelfLearningDimmer)obj).unit == unit;
|
||||
return false;
|
||||
}
|
||||
public String getProtocolName() { return NexaSelfLearningProtocol.PROTOCOL; }
|
||||
@Override
|
||||
public String getModelName() { return NexaSelfLearningProtocol.MODEL; }
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -90,7 +81,15 @@ public class NexaSelfLearningDimmer implements HalEventConfig,TellstickDevice {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName() { return NexaSelfLearningProtocol.PROTOCOL; }
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof NexaSelfLearningDimmer)
|
||||
return ((NexaSelfLearningDimmer) obj).house == house &&
|
||||
((NexaSelfLearningDimmer)obj).unit == unit;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String getModelName() { return NexaSelfLearningProtocol.MODEL; }
|
||||
public String toString(){
|
||||
return "house:" + house +
|
||||
", unit:" + unit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package se.hal.plugin.tellstick.device;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
|
|
@ -18,7 +19,7 @@ import java.util.logging.Logger;
|
|||
/**
|
||||
* Created by Ziver on 2015-11-19.
|
||||
*/
|
||||
public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice {
|
||||
public class Oregon0x1A2D implements TellstickDevice, HalSensorConfig {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
public enum OregonSensorType{
|
||||
|
|
@ -52,17 +53,11 @@ public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice {
|
|||
return sensorType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(! (obj instanceof Oregon0x1A2D))
|
||||
return false;
|
||||
return ((Oregon0x1A2D)obj).address == this.address &&
|
||||
((Oregon0x1A2D)obj).sensorType == this.sensorType;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return "address:"+address+",sensorType:"+ sensorType;
|
||||
}
|
||||
@Override
|
||||
public String getProtocolName() { return Oregon0x1A2DProtocol.PROTOCOL; }
|
||||
@Override
|
||||
public String getModelName() { return Oregon0x1A2DProtocol.MODEL; }
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -95,7 +90,15 @@ public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolName() { return Oregon0x1A2DProtocol.PROTOCOL; }
|
||||
public boolean equals(Object obj){
|
||||
if(obj instanceof Oregon0x1A2D)
|
||||
return ((Oregon0x1A2D)obj).address == this.address &&
|
||||
((Oregon0x1A2D)obj).sensorType == this.sensorType;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String getModelName() { return Oregon0x1A2DProtocol.MODEL; }
|
||||
public String toString(){
|
||||
return "address:" + address + ",sensorType:" + sensorType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,44 +3,45 @@ package se.hal.plugin.tellstick;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.DimmerEventData;
|
||||
import zutil.converter.Converter;
|
||||
import se.hal.plugin.tellstick.test.TestEventDevice;
|
||||
import se.hal.plugin.tellstick.test.TestProtocol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-11-19.
|
||||
*/
|
||||
public class TelstickSerialCommEventTest {
|
||||
public class TellstickSerialCommEventTest {
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
TellstickParser.registerProtocol(TestEvent.class);
|
||||
public void init() {
|
||||
TellstickParser.registerProtocol(TestProtocol.class);
|
||||
}
|
||||
|
||||
|
||||
//############# Non crashing TC
|
||||
// ----------------------------------------------------
|
||||
// Non crashing TC
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void startup(){
|
||||
public void startup() {
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
tellstick.handleLine("+V2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unregisteredListener(){
|
||||
public void unregisteredListener() {
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:1234;");
|
||||
}
|
||||
|
||||
|
||||
//############ Normal TCs
|
||||
// ----------------------------------------------------
|
||||
// Normal TCs
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void receiveUnregisteredEvent(){
|
||||
public void receiveUnregisteredEvent() {
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
||||
|
|
@ -51,14 +52,14 @@ public class TelstickSerialCommEventTest {
|
|||
}
|
||||
});
|
||||
// Execution
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:6345;");
|
||||
assertEquals("Events first transmission", 0, list.size());
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:6345;");
|
||||
assertEquals("Events Second transmission", 1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveEvent(){
|
||||
public void receiveEvent() {
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
||||
|
|
@ -69,45 +70,13 @@ public class TelstickSerialCommEventTest {
|
|||
}
|
||||
});
|
||||
// Execution
|
||||
TestEvent event = new TestEvent();
|
||||
TestEventDevice event = new TestEventDevice();
|
||||
event.testData = 0xAAAA;
|
||||
tellstick.register(event);
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:AAAA;");
|
||||
// Verification
|
||||
assertEquals("Nr of received events", 1, list.size());
|
||||
assertEquals("Data", event.testData, ((TestEvent)list.get(0)).testData);
|
||||
assertEquals("Data", event.testData, ((TestEventDevice)list.get(0)).testData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static class TestEvent extends TellstickProtocol implements HalEventConfig,TellstickDevice {
|
||||
public int testData;
|
||||
|
||||
public TestEvent(){
|
||||
super("test-prot", "test-model");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TellstickDecodedEntry> decode(byte[] data) {
|
||||
testData = Converter.toInt(data);
|
||||
|
||||
ArrayList<TellstickDecodedEntry> list = new ArrayList<>();
|
||||
list.add(new TellstickDecodedEntry(
|
||||
this, new DimmerEventData(testData, System.currentTimeMillis())
|
||||
));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() { return null; }
|
||||
@Override
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {return testData == ((TestEvent)obj).testData;}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package se.hal.plugin.tellstick;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.plugin.tellstick.test.TestProtocol;
|
||||
import se.hal.plugin.tellstick.test.TestSensorDevice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-11-19.
|
||||
*/
|
||||
public class TellstickSerialCommSensorTest {
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
TellstickParser.registerProtocol(TestProtocol.class);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Normal TCs
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void receiveUnregisteredSensor() {
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
}
|
||||
});
|
||||
// Execution
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:15;");
|
||||
assertEquals("Sensors first transmission", 0, list.size());
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:15;");
|
||||
assertEquals("Sensors Second transmission", 1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveSensor() {
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
}
|
||||
});
|
||||
// Execution
|
||||
TestSensorDevice sensor = new TestSensorDevice();
|
||||
sensor.testData = 0xAA;
|
||||
tellstick.register(sensor);
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:AA;");
|
||||
// Verification
|
||||
assertEquals("Nr of received sensors", 1, list.size());
|
||||
assertEquals("Data", sensor.testData, ((TestSensorDevice)list.get(0)).testData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package se.hal.plugin.tellstick;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-11-19.
|
||||
*/
|
||||
public class TelstickSerialCommSensorTest {
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
TellstickParser.registerProtocol(TestSensor.class);
|
||||
}
|
||||
|
||||
|
||||
//############ Normal TCs
|
||||
|
||||
@Test
|
||||
public void receiveUnregisteredSensor(){
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
}
|
||||
});
|
||||
// Execution
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||
assertEquals("Sensors first transmission", 0, list.size());
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||
assertEquals("Sensors Second transmission", 1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveSensor(){
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
}
|
||||
});
|
||||
// Execution
|
||||
TestSensor sensor = new TestSensor();
|
||||
sensor.testData = 0xAAAA;
|
||||
tellstick.register(sensor);
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:AAAA;");
|
||||
// Verification
|
||||
assertEquals("Nr of received sensors", 1, list.size());
|
||||
assertEquals("Data", sensor.testData, ((TestSensor)list.get(0)).testData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static class TestSensor extends TellstickProtocol implements HalSensorConfig,TellstickDevice {
|
||||
public int testData;
|
||||
|
||||
public TestSensor(){
|
||||
super("test-prot", "test-model");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TellstickDecodedEntry> decode(byte[] data) {
|
||||
testData = Converter.toInt(data);
|
||||
|
||||
ArrayList<TellstickDecodedEntry> list = new ArrayList<>();
|
||||
list.add(new TellstickDecodedEntry(
|
||||
this, new TemperatureSensorData(testData, 0)
|
||||
));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {return testData == ((TestSensor)obj).testData;}
|
||||
|
||||
|
||||
@Override
|
||||
public long getDataInterval() { return 0; }
|
||||
@Override
|
||||
public AggregationMethod getAggregationMethod() { return null; }
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() { return null; }
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package se.hal.plugin.tellstick.test;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.plugin.tellstick.TellstickDevice;
|
||||
import se.hal.plugin.tellstick.TellstickSerialCommEventTest;
|
||||
|
||||
public class TestEventDevice implements TellstickDevice, HalEventConfig {
|
||||
public int testData;
|
||||
|
||||
|
||||
@Override
|
||||
public String getProtocolName() {
|
||||
return "test-prot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "test-model";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return testData == ((TestEventDevice) obj).testData;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package se.hal.plugin.tellstick.test;
|
||||
|
||||
import se.hal.plugin.tellstick.TellstickProtocol;
|
||||
import se.hal.struct.devicedata.DimmerEventData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestProtocol extends TellstickProtocol {
|
||||
|
||||
public TestProtocol() {
|
||||
super("test-prot", "test-model");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TellstickDecodedEntry> decode(byte[] data) {
|
||||
ArrayList<TellstickDecodedEntry> list = new ArrayList<>();
|
||||
int parsedData = Converter.toInt(data);
|
||||
|
||||
if (parsedData > 5000) {
|
||||
TestEventDevice device = new TestEventDevice();
|
||||
device.testData = Converter.toInt(data);
|
||||
|
||||
list.add(new TellstickDecodedEntry(
|
||||
device, new DimmerEventData(device.testData, System.currentTimeMillis())
|
||||
));
|
||||
} else {
|
||||
TestSensorDevice device = new TestSensorDevice();
|
||||
device.testData = Converter.toInt(data);
|
||||
|
||||
list.add(new TellstickDecodedEntry(
|
||||
device, new TemperatureSensorData(device.testData, System.currentTimeMillis())
|
||||
));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package se.hal.plugin.tellstick.test;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
import se.hal.plugin.tellstick.TellstickDevice;
|
||||
import se.hal.plugin.tellstick.TellstickSerialCommSensorTest;
|
||||
|
||||
public class TestSensorDevice implements HalSensorConfig, TellstickDevice {
|
||||
public int testData;
|
||||
|
||||
@Override
|
||||
public String getProtocolName() {
|
||||
return "test-prot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "test-model";
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDataInterval() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregationMethod getAggregationMethod() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return testData == ((TestSensorDevice) obj).testData;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
dependencies {
|
||||
def ZIGBEE_LIB_VERSION = "1.3.10"
|
||||
//def ZIGBEE_LIB_VERSION = "1.3.11-SNAPSHOT"
|
||||
|
||||
implementation project(':hal-core')
|
||||
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
|
|||
private final FlowControl flowControl;
|
||||
|
||||
private SerialPort serialPort;
|
||||
private InputStream serialInputstream;
|
||||
private OutputStream serialOutputstream;
|
||||
private InputStream serialInputStream;
|
||||
private OutputStream serialOutputStream;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -140,8 +140,8 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
|
|||
throw new RuntimeException("Error opening serial port: " + portName);
|
||||
}
|
||||
|
||||
serialInputstream = serialPort.getInputStream();
|
||||
serialOutputstream = serialPort.getOutputStream();
|
||||
serialInputStream = serialPort.getInputStream();
|
||||
serialOutputStream = serialPort.getOutputStream();
|
||||
|
||||
switch (flowControl) {
|
||||
case FLOWCONTROL_OUT_NONE:
|
||||
|
|
@ -170,8 +170,8 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
|
|||
purgeRxBuffer();
|
||||
serialPort.closePort();
|
||||
|
||||
serialInputstream = null;
|
||||
serialOutputstream = null;
|
||||
serialInputStream = null;
|
||||
serialOutputStream = null;
|
||||
serialPort = null;
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error closing portName portName: '" + portName + "'", e);
|
||||
|
|
@ -180,11 +180,11 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
|
|||
|
||||
@Override
|
||||
public void write(int value) {
|
||||
if (serialOutputstream == null)
|
||||
if (serialOutputStream == null)
|
||||
throw new RuntimeException("Unable to write, Serial port is not open.");
|
||||
|
||||
try {
|
||||
serialOutputstream.write(value);
|
||||
serialOutputStream.write(value);
|
||||
} catch (IOException e) {
|
||||
logger.error("Was unable to write to serial port.", e);
|
||||
}
|
||||
|
|
@ -197,14 +197,14 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
|
|||
|
||||
@Override
|
||||
public int read(int timeout) {
|
||||
if (serialInputstream == null)
|
||||
if (serialInputStream == null)
|
||||
throw new RuntimeException("Unable to read, Serial port is not open.");
|
||||
|
||||
try {
|
||||
if (serialPort.getReadTimeout() != timeout)
|
||||
serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING, timeout, 0);
|
||||
|
||||
return serialInputstream.read();
|
||||
return serialInputStream.read();
|
||||
} catch (IOException e) {
|
||||
logger.error("Was unable to read from serial port.", e);
|
||||
}
|
||||
|
|
@ -213,11 +213,11 @@ public class ZigBeeJSerialCommPort implements ZigBeePort {
|
|||
|
||||
@Override
|
||||
public void purgeRxBuffer() {
|
||||
if (serialOutputstream == null)
|
||||
if (serialOutputStream == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
serialOutputstream.flush();
|
||||
serialOutputStream.flush();
|
||||
} catch (IOException e) {
|
||||
logger.error("Was unable to flush serial data.", e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue