diff --git a/src/se/hal/plugin/raspberry/RPiController.java b/src/se/hal/plugin/raspberry/RPiController.java index 05928eea..dc819523 100755 --- a/src/se/hal/plugin/raspberry/RPiController.java +++ b/src/se/hal/plugin/raspberry/RPiController.java @@ -1,5 +1,6 @@ package se.hal.plugin.raspberry; +import se.hal.intf.HalDeviceData; import se.hal.intf.HalSensorController; import se.hal.intf.HalSensorConfig; import se.hal.intf.HalSensorReportListener; @@ -89,9 +90,9 @@ public class RPiController implements HalSensorController { } } - public void sendDataReport(HalSensorConfig sensorConfig){ + public void sendDataReport(HalSensorConfig sensorConfig, HalDeviceData sensorData){ if(sensorListener != null){ - sensorListener.reportReceived(sensorConfig); + sensorListener.reportReceived(sensorConfig, sensorData); }else{ logger.log(Level.WARNING, "Could not report data. No registered listener"); } diff --git a/src/se/hal/plugin/raspberry/RPiPowerConsumptionSensor.java b/src/se/hal/plugin/raspberry/RPiPowerConsumptionSensor.java index dfb53256..c88e31fa 100755 --- a/src/se/hal/plugin/raspberry/RPiPowerConsumptionSensor.java +++ b/src/se/hal/plugin/raspberry/RPiPowerConsumptionSensor.java @@ -11,11 +11,8 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig { private int gpioPin = -1; - public RPiPowerConsumptionSensor(){ - //need to be empty for the framework to create an instance - } - - public RPiPowerConsumptionSensor(int gpioPin) { + public RPiPowerConsumptionSensor(){ } //need to be empty for the framework to create an instance + public RPiPowerConsumptionSensor(int gpioPin) { this.gpioPin = gpioPin; } @@ -38,9 +35,9 @@ public class RPiPowerConsumptionSensor implements HalSensorConfig { @Override public boolean equals(Object obj){ - if(!(obj instanceof RPiPowerConsumptionSensor)) - return false; - return ((RPiPowerConsumptionSensor)obj).gpioPin == gpioPin; + if(obj instanceof RPiPowerConsumptionSensor) + return ((RPiPowerConsumptionSensor)obj).gpioPin == gpioPin; + return false; } public int getGpioPin() { diff --git a/src/se/hal/plugin/raspberry/RPiTemperatureSensor.java b/src/se/hal/plugin/raspberry/RPiTemperatureSensor.java index c1be5faf..4d7bf698 100755 --- a/src/se/hal/plugin/raspberry/RPiTemperatureSensor.java +++ b/src/se/hal/plugin/raspberry/RPiTemperatureSensor.java @@ -8,10 +8,15 @@ import zutil.ui.Configurator; public class RPiTemperatureSensor implements HalSensorConfig { @Configurator.Configurable("1-Wire Address") - private String w1Address = null; + private String w1Address; - + + public RPiTemperatureSensor() { } + public RPiTemperatureSensor(String w1Address) { + this.w1Address = w1Address; + } + @Override public long getDataInterval() { @@ -30,8 +35,8 @@ public class RPiTemperatureSensor implements HalSensorConfig { @Override public boolean equals(Object obj){ - if(obj instanceof RPiTemperatureSensor) - return obj == this; + if(obj instanceof RPiTemperatureSensor && w1Address != null) + return this.get1WAddress().equals(((RPiTemperatureSensor) obj).w1Address); return false; } diff --git a/src/se/hal/plugin/raspberry/hardware/RPiDS18B20.java b/src/se/hal/plugin/raspberry/hardware/RPiDS18B20.java index 7326b2fa..77d9f78b 100755 --- a/src/se/hal/plugin/raspberry/hardware/RPiDS18B20.java +++ b/src/se/hal/plugin/raspberry/hardware/RPiDS18B20.java @@ -6,6 +6,7 @@ import com.pi4j.temperature.TemperatureScale; import se.hal.plugin.raspberry.RPiController; import se.hal.plugin.raspberry.RPiSensor; import se.hal.plugin.raspberry.RPiTemperatureSensor; +import se.hal.struct.devicedata.TemperatureSensorData; import zutil.log.LogUtil; import java.util.concurrent.Executors; @@ -54,7 +55,11 @@ public class RPiDS18B20 implements RPiSensor, Runnable { for(TemperatureSensor device : w1Mater.getDevices(TemperatureSensor.class)){ if(device.getName().equals(w1Address)){ controller.sendDataReport( - new RPiTemperatureSensor(System.currentTimeMillis(), device.getTemperature(TemperatureScale.CELSIUS))); + new RPiTemperatureSensor(w1Address), + new TemperatureSensorData( + System.currentTimeMillis(), + device.getTemperature(TemperatureScale.CELSIUS) + )); break; } } diff --git a/src/se/hal/plugin/raspberry/hardware/RPiInteruptPulseFlankCounter.java b/src/se/hal/plugin/raspberry/hardware/RPiInteruptPulseFlankCounter.java index 153cbe53..967ca561 100755 --- a/src/se/hal/plugin/raspberry/hardware/RPiInteruptPulseFlankCounter.java +++ b/src/se/hal/plugin/raspberry/hardware/RPiInteruptPulseFlankCounter.java @@ -8,6 +8,7 @@ import se.hal.plugin.raspberry.RPiController; import se.hal.plugin.raspberry.RPiPowerConsumptionSensor; import se.hal.plugin.raspberry.RPiSensor; import se.hal.plugin.raspberry.RPiUtility; +import se.hal.struct.devicedata.PowerConsumptionSensorData; import zutil.log.LogUtil; import java.util.concurrent.ExecutorService; @@ -132,7 +133,11 @@ public class RPiInteruptPulseFlankCounter implements Runnable, GpioPinListenerDi @Override public void run() { logger.log(Level.INFO, "Reporting data. timestamp_end="+timestamp_end+", data="+data); - controller.sendDataReport(new RPiPowerConsumptionSensor(gpioPin, timestamp_end, data)); + controller.sendDataReport( + new RPiPowerConsumptionSensor(gpioPin), + new PowerConsumptionSensorData( + timestamp_end, data + )); } }); } diff --git a/src/se/hal/plugin/tellstick/TellstickSerialComm.java b/src/se/hal/plugin/tellstick/TellstickSerialComm.java index 872a8f9a..014f93b5 100755 --- a/src/se/hal/plugin/tellstick/TellstickSerialComm.java +++ b/src/se/hal/plugin/tellstick/TellstickSerialComm.java @@ -213,22 +213,24 @@ public class TellstickSerialComm implements Runnable, public void register(HalEventConfig event) { if(event instanceof TellstickDevice) registeredDevices.add((TellstickDevice) event); + else throw new IllegalArgumentException( + "Device configuration is not an instance of "+TellstickDevice.class+": "+event.getClass()); } @Override public void register(HalSensorConfig sensor) { if(sensor instanceof TellstickDevice) registeredDevices.add((TellstickDevice) sensor); + else throw new IllegalArgumentException( + "Device configuration is not an instance of "+TellstickDevice.class+": "+sensor.getClass()); } @Override public void deregister(HalEventConfig event) { - if(event instanceof TellstickDevice) - registeredDevices.remove(event); + registeredDevices.remove(event); } @Override public void deregister(HalSensorConfig sensor) { - if(sensor instanceof TellstickDevice) - registeredDevices.remove(sensor); + registeredDevices.remove(sensor); } @Override diff --git a/src/se/hal/struct/devicedata/DimmerEventData.java b/src/se/hal/struct/devicedata/DimmerEventData.java index 8237ef73..4b60fd0c 100755 --- a/src/se/hal/struct/devicedata/DimmerEventData.java +++ b/src/se/hal/struct/devicedata/DimmerEventData.java @@ -32,6 +32,12 @@ public class DimmerEventData extends HalEventData { private double dimmValue; + public DimmerEventData() { } + public DimmerEventData(double dimmValue) { + this.dimmValue = dimmValue; + } + + @Override public double getData() { return dimmValue; diff --git a/src/se/hal/struct/devicedata/PowerConsumptionSensorData.java b/src/se/hal/struct/devicedata/PowerConsumptionSensorData.java index 77b727f2..b23aba27 100755 --- a/src/se/hal/struct/devicedata/PowerConsumptionSensorData.java +++ b/src/se/hal/struct/devicedata/PowerConsumptionSensorData.java @@ -10,6 +10,18 @@ public class PowerConsumptionSensorData extends HalSensorData { private double wattHours; + + public PowerConsumptionSensorData() { } + public PowerConsumptionSensorData(double wattHours) { + this.wattHours = wattHours; + } + public PowerConsumptionSensorData(long timestamp, double wattHours) { + this(wattHours); + super.setTimestamp(timestamp); + } + + + public void setConsumption(double wattHours){ this.wattHours = wattHours; } diff --git a/src/se/hal/struct/devicedata/TemperatureSensorData.java b/src/se/hal/struct/devicedata/TemperatureSensorData.java index 7bc31799..507c36fa 100755 --- a/src/se/hal/struct/devicedata/TemperatureSensorData.java +++ b/src/se/hal/struct/devicedata/TemperatureSensorData.java @@ -14,11 +14,15 @@ public class TemperatureSensorData extends HalSensorData { public TemperatureSensorData(double temperature){ this.temperature = temperature; } + public TemperatureSensorData(long timestamp, double temperature){ + this(temperature); + super.setTimestamp(timestamp); + } /** * @param data the temperature to set in degrees C */ - public void setData(double data){ + public void setTemperature(double data){ this.temperature = data; } @@ -29,4 +33,5 @@ public class TemperatureSensorData extends HalSensorData { public double getData() { return temperature; } + } diff --git a/test/se/hal/plugin/tellstick/TelstickSerialCommTest.java b/test/se/hal/plugin/tellstick/TelstickSerialCommTest.java index d31a0bd2..bad82ee4 100755 --- a/test/se/hal/plugin/tellstick/TelstickSerialCommTest.java +++ b/test/se/hal/plugin/tellstick/TelstickSerialCommTest.java @@ -41,7 +41,7 @@ public class TelstickSerialCommTest { //############ Normal TCs @Test - public void unregisteredEvent(){ + public void receiveUnregisteredEvent(){ // Setup TellstickSerialComm tellstick = new TellstickSerialComm(); final ArrayList list = new ArrayList<>(); @@ -59,7 +59,7 @@ public class TelstickSerialCommTest { } @Test - public void event(){ + public void receiveEvent(){ // Setup TellstickSerialComm tellstick = new TellstickSerialComm(); final ArrayList list = new ArrayList<>(); @@ -81,6 +81,7 @@ public class TelstickSerialCommTest { + private static class TestEvent extends TellstickProtocol implements HalEventConfig,TellstickDevice { public int testData; @@ -105,6 +106,5 @@ public class TelstickSerialCommTest { @Override public boolean equals(Object obj) {return testData == ((TestEvent)obj).testData;} - } }