Split switch event data into multiple classes
This commit is contained in:
parent
4499824965
commit
6214c01157
23 changed files with 259 additions and 96 deletions
|
|
@ -4,7 +4,7 @@ import se.hal.ControllerManager;
|
|||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
import se.hal.util.DeviceNameComparator;
|
||||
import se.hal.util.HistoryDataListSqlResult;
|
||||
import se.hal.util.HistoryDataListSqlResult.HistoryData;
|
||||
|
|
@ -15,7 +15,6 @@ import zutil.log.LogUtil;
|
|||
import zutil.parser.Templator;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -46,7 +45,7 @@ public class EventOverviewWebPage extends HalWebPage {
|
|||
int id = (ObjectUtil.isEmpty(request.get("action_id")) ? -1 : Integer.parseInt(request.get("action_id")));
|
||||
|
||||
// change event data
|
||||
SwitchEventData eventData = new SwitchEventData();
|
||||
OnOffEventData eventData = new OnOffEventData();
|
||||
if (request.containsKey("enabled") && "on".equals(request.get("enabled")))
|
||||
eventData.turnOn();
|
||||
else
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.hal.struct.devicedata;
|
||||
|
||||
import se.hal.intf.HalEventData;
|
||||
|
||||
|
||||
public class AvailabilityEventData extends HalEventData {
|
||||
|
||||
private boolean available;
|
||||
|
||||
|
||||
public AvailabilityEventData() { }
|
||||
public AvailabilityEventData(boolean available, long timestamp) {
|
||||
this.available = available;
|
||||
this.setTimestamp(timestamp);
|
||||
}
|
||||
|
||||
public void setAvailable(){
|
||||
available = true;
|
||||
}
|
||||
public void setUnavailable(){
|
||||
available = false;
|
||||
}
|
||||
public void toggle(){
|
||||
available = !available;
|
||||
}
|
||||
|
||||
public boolean isAvailable(){
|
||||
return available;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return available ? "Available" : "Unavailable";
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Storage methods
|
||||
// ----------------------------------------
|
||||
|
||||
@Override
|
||||
public double getData() {
|
||||
return (available ? 1.0 : 0.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(double enabled) {
|
||||
this.available = enabled > 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ package se.hal.struct.devicedata;
|
|||
|
||||
import se.hal.intf.HalEventData;
|
||||
|
||||
|
||||
public class DimmerEventData extends HalEventData {
|
||||
|
||||
private double dimmValue;
|
||||
|
|
@ -36,6 +37,15 @@ public class DimmerEventData extends HalEventData {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return dimmValue+"%";
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Storage methods
|
||||
// ----------------------------------------
|
||||
|
||||
/**
|
||||
* @return the dim level from 0.0 to 1.0
|
||||
*/
|
||||
|
|
@ -43,13 +53,9 @@ public class DimmerEventData extends HalEventData {
|
|||
public double getData() {
|
||||
return dimmValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(double dimmValue) {
|
||||
this.dimmValue = dimmValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return dimmValue+"%";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,15 @@ public class HumiditySensorData extends HalSensorData {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return humidity+"%";
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Storage methods
|
||||
// ----------------------------------------
|
||||
|
||||
@Override
|
||||
public double getData() {
|
||||
return humidity;
|
||||
|
|
@ -23,9 +32,4 @@ public class HumiditySensorData extends HalSensorData {
|
|||
public void setData(double humidity) {
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return humidity+"%";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,15 @@ public class LightSensorData extends HalSensorData {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return lux+" lux";
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Storage methods
|
||||
// ----------------------------------------
|
||||
|
||||
/**
|
||||
* @return the light intensity in lux
|
||||
*/
|
||||
|
|
@ -21,6 +30,7 @@ public class LightSensorData extends HalSensorData {
|
|||
public double getData() {
|
||||
return lux;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lux set the light intensity in lux
|
||||
*/
|
||||
|
|
@ -28,9 +38,4 @@ public class LightSensorData extends HalSensorData {
|
|||
public void setData(double lux) {
|
||||
this.lux = lux;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return lux+" lux";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,39 +24,49 @@ package se.hal.struct.devicedata;
|
|||
|
||||
import se.hal.intf.HalEventData;
|
||||
|
||||
public class SwitchEventData extends HalEventData {
|
||||
|
||||
private boolean enabled;
|
||||
public class OnOffEventData extends HalEventData {
|
||||
|
||||
private boolean isOn;
|
||||
|
||||
|
||||
public SwitchEventData() { }
|
||||
public SwitchEventData(boolean enabled, long timestamp) {
|
||||
this.enabled = enabled;
|
||||
public OnOffEventData() { }
|
||||
public OnOffEventData(boolean isOn, long timestamp) {
|
||||
this.isOn = isOn;
|
||||
this.setTimestamp(timestamp);
|
||||
}
|
||||
|
||||
|
||||
public void turnOn(){
|
||||
enabled = true;
|
||||
isOn = true;
|
||||
}
|
||||
public void turnOff(){
|
||||
enabled = false;
|
||||
isOn = false;
|
||||
}
|
||||
public void toggle(){
|
||||
isOn = !isOn;
|
||||
}
|
||||
|
||||
public boolean isOn(){
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getData() {
|
||||
return (enabled ? 1.0 : 0.0);
|
||||
}
|
||||
@Override
|
||||
public void setData(double enabled) {
|
||||
this.enabled = enabled > 0;
|
||||
return isOn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return enabled ? "ON" : "OFF";
|
||||
return isOn ? "ON" : "OFF";
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Storage methods
|
||||
// ----------------------------------------
|
||||
|
||||
@Override
|
||||
public double getData() {
|
||||
return (isOn ? 1.0 : 0.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(double enabled) {
|
||||
this.isOn = enabled > 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Ziver
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package se.hal.struct.devicedata;
|
||||
|
||||
import se.hal.intf.HalEventData;
|
||||
|
||||
|
||||
public class OpenClosedEventData extends HalEventData {
|
||||
|
||||
private boolean isOpen;
|
||||
|
||||
|
||||
public OpenClosedEventData() { }
|
||||
public OpenClosedEventData(boolean isOpen, long timestamp) {
|
||||
this.isOpen = isOpen;
|
||||
this.setTimestamp(timestamp);
|
||||
}
|
||||
|
||||
public void open(){
|
||||
isOpen = true;
|
||||
}
|
||||
public void close(){
|
||||
isOpen = false;
|
||||
}
|
||||
public void toggle(){
|
||||
isOpen = !isOpen;
|
||||
}
|
||||
|
||||
public boolean isOpen(){
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return isOpen ? "Open" : "Closed";
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Storage methods
|
||||
// ----------------------------------------
|
||||
|
||||
@Override
|
||||
public double getData() {
|
||||
return (isOpen ? 1.0 : 0.0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(double enabled) {
|
||||
this.isOpen = enabled > 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,12 +2,12 @@ package se.hal.struct.devicedata;
|
|||
|
||||
import se.hal.intf.HalSensorData;
|
||||
|
||||
|
||||
public class PowerConsumptionSensorData extends HalSensorData {
|
||||
|
||||
private double wattHours;
|
||||
|
||||
|
||||
|
||||
public PowerConsumptionSensorData() { }
|
||||
public PowerConsumptionSensorData(double wattHours, long timestamp) {
|
||||
this.wattHours = wattHours;
|
||||
|
|
@ -15,6 +15,15 @@ public class PowerConsumptionSensorData extends HalSensorData {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return wattHours+" Wh";
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Storage methods
|
||||
// ----------------------------------------
|
||||
|
||||
/**
|
||||
* @return int representing Watt/Hour
|
||||
*/
|
||||
|
|
@ -22,13 +31,9 @@ public class PowerConsumptionSensorData extends HalSensorData {
|
|||
public double getData() {
|
||||
return wattHours;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(double wattHours){
|
||||
this.wattHours = wattHours;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return wattHours+" Wh";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package se.hal.struct.devicedata;
|
|||
|
||||
import se.hal.intf.HalSensorData;
|
||||
|
||||
|
||||
public class TemperatureSensorData extends HalSensorData {
|
||||
|
||||
private double temperature;
|
||||
|
|
@ -14,6 +15,15 @@ public class TemperatureSensorData extends HalSensorData {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return temperature + " C";
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Storage methods
|
||||
// ----------------------------------------
|
||||
|
||||
/**
|
||||
* @return temperature in degrees C
|
||||
*/
|
||||
|
|
@ -21,6 +31,7 @@ public class TemperatureSensorData extends HalSensorData {
|
|||
public double getData() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param temperature the temperature to set in degrees C
|
||||
*/
|
||||
|
|
@ -28,10 +39,4 @@ public class TemperatureSensorData extends HalSensorData {
|
|||
public void setData(double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return temperature + " C";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package se.hal;
|
|||
import org.junit.Test;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ public class EventControllerManagerTest {
|
|||
|
||||
private ControllerManager manager = new ControllerManager();
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void addAvailableEvent(){
|
||||
assertEquals(0, manager.getAvailableEvents().size());
|
||||
|
|
@ -90,7 +90,7 @@ public class EventControllerManagerTest {
|
|||
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
return SwitchEventData.class;
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ public class EventControllerManagerTest {
|
|||
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
return SwitchEventData.class;
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ public class EventControllerManagerTest {
|
|||
|
||||
@Override
|
||||
public void setListener(HalEventReportListener listener) { }
|
||||
|
||||
|
||||
@Override
|
||||
public void close() { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ hal.http_port=8080
|
|||
|
||||
## Zigbee plugin
|
||||
#zigbee.com_port=COM4
|
||||
#zigbee.pan_id=-6480
|
||||
|
||||
## ZWave plugin
|
||||
#zwave.com_port=COM4
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class DeviceTraitFactory {
|
|||
public static DeviceTrait[] getTraits(Sensor sensor) {
|
||||
switch (sensor.getDeviceData().getClass().getName()) {
|
||||
case "se.hal.struct.devicedata.DimmerEventData":
|
||||
case "se.hal.struct.devicedata.SwitchEventData":
|
||||
case "se.hal.struct.devicedata.OnOffEventData":
|
||||
return new DeviceTrait[]{};
|
||||
|
||||
case "se.hal.struct.devicedata.PowerConsumptionSensorData":
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ public enum DeviceType {
|
|||
public static DeviceType getType(Sensor sensor) {
|
||||
switch (sensor.getDeviceData().getClass().getName()) {
|
||||
case "se.hal.struct.devicedata.DimmerEventData":
|
||||
case "se.hal.struct.devicedata.SwitchEventData":
|
||||
case "se.hal.struct.devicedata.OnOffEventData":
|
||||
return LIGHT;
|
||||
|
||||
case "se.hal.struct.devicedata.PowerConsumptionSensorData":
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
package se.hal.plugin.dummy;
|
||||
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.HumiditySensorData;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
|
||||
public class DummySwitchEvent implements DummyDevice, HalEventConfig {
|
||||
|
||||
|
||||
@Override
|
||||
public HalDeviceData generateData() {
|
||||
return new SwitchEventData(
|
||||
return new OnOffEventData(
|
||||
(int) (Math.random() * 10) < 5,
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
|
|
@ -24,6 +22,6 @@ public class DummySwitchEvent implements DummyDevice, HalEventConfig {
|
|||
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
return SwitchEventData.class;
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ package se.hal.plugin.netscan;
|
|||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.AvailabilityEventData;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
import zutil.InetUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.InetScanner;
|
||||
|
|
@ -27,7 +28,7 @@ public class NetScanController implements HalEventController, HalAutoScannableCo
|
|||
private ScheduledExecutorService executor;
|
||||
private HalEventReportListener listener;
|
||||
/** A register and a cache of previous state **/
|
||||
private HashMap<NetworkDevice,SwitchEventData> devices = new HashMap<>();
|
||||
private HashMap<NetworkDevice, AvailabilityEventData> devices = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
|
|
@ -61,9 +62,9 @@ public class NetScanController implements HalEventController, HalAutoScannableCo
|
|||
@Override
|
||||
public void run() {
|
||||
try(MultiCommandExecutor executor = new MultiCommandExecutor()){
|
||||
for (Map.Entry<NetworkDevice,SwitchEventData> entry : devices.entrySet()) {
|
||||
for (Map.Entry<NetworkDevice, AvailabilityEventData> entry : devices.entrySet()) {
|
||||
NetworkDevice device = entry.getKey();
|
||||
SwitchEventData prevData = entry.getValue();
|
||||
AvailabilityEventData prevData = entry.getValue();
|
||||
if (listener != null) {
|
||||
// We ping two times to increase reliability
|
||||
boolean ping = false;
|
||||
|
|
@ -72,10 +73,10 @@ public class NetScanController implements HalEventController, HalAutoScannableCo
|
|||
ping |= InetScanner.isReachable(device.getHost(), executor);
|
||||
|
||||
// Should we report?
|
||||
if (prevData == null || prevData.isOn() != ping) {
|
||||
SwitchEventData newData = new SwitchEventData(ping, System.currentTimeMillis());
|
||||
if (prevData == null || prevData.isAvailable() != ping) {
|
||||
AvailabilityEventData newData = new AvailabilityEventData(ping, System.currentTimeMillis());
|
||||
entry.setValue(newData);
|
||||
logger.fine("IP "+device.getHost() +" state has changed to "+ newData.isOn());
|
||||
logger.fine("IP " + device.getHost() + " state has changed to " + newData);
|
||||
listener.reportReceived(device, newData);
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +91,7 @@ public class NetScanController implements HalEventController, HalAutoScannableCo
|
|||
if (listener != null)
|
||||
listener.reportReceived(
|
||||
new NetworkDevice(ip.getHostAddress()),
|
||||
new SwitchEventData(true, System.currentTimeMillis()));
|
||||
new OnOffEventData(true, System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package se.hal.plugin.netscan;
|
|||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
import zutil.ui.Configurator;
|
||||
|
||||
public class NetworkDevice implements HalEventConfig {
|
||||
|
|
@ -40,6 +40,6 @@ public class NetworkDevice implements HalEventConfig {
|
|||
}
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
return SwitchEventData.class;
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,14 +25,11 @@ package se.hal.plugin.tellstick.device;
|
|||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.intf.HalSensorData;
|
||||
import se.hal.plugin.tellstick.TellstickDevice;
|
||||
import se.hal.plugin.tellstick.TellstickDeviceGroup;
|
||||
import se.hal.plugin.tellstick.TellstickSerialComm;
|
||||
import se.hal.plugin.tellstick.protocol.NexaSelfLearningProtocol;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import zutil.parser.binary.BinaryStruct;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
import zutil.ui.Configurator;
|
||||
|
||||
/**
|
||||
|
|
@ -109,7 +106,7 @@ public class NexaSelfLearning implements HalEventConfig,TellstickDevice,Tellstic
|
|||
}
|
||||
@Override
|
||||
public Class<? extends HalEventData> getEventDataClass() {
|
||||
return SwitchEventData.class;
|
||||
return OnOffEventData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,11 +26,9 @@ 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.TellstickDeviceGroup;
|
||||
import se.hal.plugin.tellstick.TellstickSerialComm;
|
||||
import se.hal.plugin.tellstick.protocol.NexaSelfLearningProtocol;
|
||||
import se.hal.struct.devicedata.DimmerEventData;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import zutil.ui.Configurator;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,14 +24,13 @@ package se.hal.plugin.tellstick.protocol;
|
|||
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.plugin.tellstick.TellstickSerialComm;
|
||||
import se.hal.plugin.tellstick.cmd.TellstickCmd;
|
||||
import se.hal.plugin.tellstick.cmd.TellstickCmdExtendedSend;
|
||||
import se.hal.plugin.tellstick.TellstickProtocol;
|
||||
import se.hal.plugin.tellstick.device.NexaSelfLearning;
|
||||
import se.hal.plugin.tellstick.device.NexaSelfLearningDimmer;
|
||||
import se.hal.struct.devicedata.DimmerEventData;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
import zutil.ByteUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.parser.binary.BinaryStruct;
|
||||
|
|
@ -84,8 +83,8 @@ public class NexaSelfLearningProtocol extends TellstickProtocol {
|
|||
logger.severe("Device config is not instance of NexaSelfLearning: "+deviceConfig.getClass());
|
||||
return null;
|
||||
}
|
||||
if ( ! (deviceData instanceof SwitchEventData || deviceData instanceof DimmerEventData)){
|
||||
logger.severe("Device data is not an instance of SwitchEventData or DimmerEventData: "+deviceData.getClass());
|
||||
if ( ! (deviceData instanceof OnOffEventData || deviceData instanceof DimmerEventData)){
|
||||
logger.severe("Device data is not an instance of OnOffEventData or DimmerEventData: "+deviceData.getClass());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +101,7 @@ public class NexaSelfLearningProtocol extends TellstickProtocol {
|
|||
struct.house = ((NexaSelfLearning) deviceConfig).getHouse();
|
||||
struct.group = ((NexaSelfLearning) deviceConfig).getGroup();
|
||||
struct.unit = ((NexaSelfLearning) deviceConfig).getUnit();
|
||||
struct.enable = ((SwitchEventData) deviceData).isOn();
|
||||
struct.enable = ((OnOffEventData) deviceData).isOn();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -163,7 +162,7 @@ public class NexaSelfLearningProtocol extends TellstickProtocol {
|
|||
*/
|
||||
list.add(new TellstickDecodedEntry(
|
||||
new NexaSelfLearning(struct.house, struct.group, struct.unit),
|
||||
new SwitchEventData(struct.enable, System.currentTimeMillis())
|
||||
new OnOffEventData(struct.enable, System.currentTimeMillis())
|
||||
));
|
||||
/* }*/
|
||||
return list;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.DimmerEventData;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
package se.hal.plugin.tellstick;
|
||||
|
||||
import se.hal.plugin.tellstick.device.NexaSelfLearning;
|
||||
import se.hal.plugin.tellstick.protocol.NexaSelfLearningProtocol;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-11-19.
|
||||
|
|
@ -25,7 +24,7 @@ public class TelstickSerialCommNexaOnOffTest {
|
|||
nexaDevice.setGroup(false);
|
||||
nexaDevice.setUnit(1);
|
||||
|
||||
SwitchEventData nexaData = new SwitchEventData();
|
||||
OnOffEventData nexaData = new OnOffEventData();
|
||||
|
||||
System.out.println("Up and Running");
|
||||
while(true) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package se.hal.plugin.tellstick;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
|
|
@ -21,7 +20,7 @@ public class TelstickSerialCommSensorTest {
|
|||
public void init(){
|
||||
TellstickParser.registerProtocol(TestSensor.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//############ Normal TCs
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,11 @@
|
|||
|
||||
package se.hal.plugin.tellstick.protocol;
|
||||
|
||||
import se.hal.plugin.tellstick.TellstickProtocol;
|
||||
import se.hal.plugin.tellstick.TellstickProtocol.TellstickDecodedEntry;
|
||||
import se.hal.plugin.tellstick.device.NexaSelfLearning;
|
||||
import se.hal.plugin.tellstick.device.NexaSelfLearningDimmer;
|
||||
import se.hal.struct.devicedata.DimmerEventData;
|
||||
import se.hal.struct.devicedata.SwitchEventData;
|
||||
import se.hal.struct.devicedata.OnOffEventData;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
|
@ -42,7 +41,7 @@ public class NexaSelfLearningTest {
|
|||
NexaSelfLearning nexaDevice = new NexaSelfLearning();
|
||||
nexaDevice.setHouse(11_772_006);
|
||||
nexaDevice.setUnit(3);
|
||||
SwitchEventData nexaData = new SwitchEventData(true, System.currentTimeMillis());
|
||||
OnOffEventData nexaData = new OnOffEventData(true, System.currentTimeMillis());
|
||||
|
||||
byte[] expected = Converter.toBytes(new char[]{
|
||||
84, // T
|
||||
|
|
@ -99,7 +98,7 @@ public class NexaSelfLearningTest {
|
|||
|
||||
assertEquals("House Code", 11772006, ((NexaSelfLearning)nexa.getDevice()).getHouse());
|
||||
assertEquals("Unit Code", 0, ((NexaSelfLearning)nexa.getDevice()).getUnit());
|
||||
assertTrue("Enabled", ((SwitchEventData)nexa.getData()).isOn());
|
||||
assertTrue("Enabled", ((OnOffEventData)nexa.getData()).isOn());
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
|
|
@ -108,7 +107,7 @@ public class NexaSelfLearningTest {
|
|||
|
||||
assertEquals("House Code", 11772006, ((NexaSelfLearning)nexa.getDevice()).getHouse());
|
||||
assertEquals("Unit Code", 0, ((NexaSelfLearning)nexa.getDevice()).getUnit());
|
||||
assertFalse("Enabled", ((SwitchEventData)nexa.getData()).isOn());
|
||||
assertFalse("Enabled", ((OnOffEventData)nexa.getData()).isOn());
|
||||
}
|
||||
|
||||
private TellstickDecodedEntry decode(String data){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue