diff --git a/src/se/hal/ControllerManager.java b/src/se/hal/ControllerManager.java index 61a0beab..9e3662e7 100755 --- a/src/se/hal/ControllerManager.java +++ b/src/se/hal/ControllerManager.java @@ -102,7 +102,7 @@ public class ControllerManager implements HalSensorReportListener, } @Override - public void reportReceived(HalSensorConfig sensorConfig, HalSensorData sensorData) { + public void reportReceived(HalSensorConfig sensorConfig, HalDeviceData sensorData) { try{ DBConnection db = HalContext.getDB(); Sensor sensor = findSensor(sensorConfig, registeredSensors); @@ -191,7 +191,7 @@ public class ControllerManager implements HalSensorReportListener, } @Override - public void reportReceived(HalEventConfig eventConfig, HalEventData eventData) { + public void reportReceived(HalEventConfig eventConfig, HalDeviceData eventData) { try { DBConnection db = HalContext.getDB(); Event event = findEvent(eventConfig, registeredEvents); @@ -234,7 +234,7 @@ public class ControllerManager implements HalSensorReportListener, public void send(Event event){ HalEventController controller = getControllerInstance(event.getController()); if(controller != null) { - controller.send(event.getDeviceConfig()); + controller.send(event.getDeviceConfig(), event.getDeviceData()); reportReceived(event.getDeviceConfig(), event.getDeviceData()); // save action to db } else diff --git a/src/se/hal/intf/HalEventController.java b/src/se/hal/intf/HalEventController.java index bf952540..c44eef7f 100755 --- a/src/se/hal/intf/HalEventController.java +++ b/src/se/hal/intf/HalEventController.java @@ -24,9 +24,10 @@ public interface HalEventController { void deregister(HalEventConfig event); /** - * @param event transmit this event if possible. + * @param eventConfig the event configuration to target when sending + * @param eventData the data to send */ - void send(HalEventConfig event); // TODO: where to put data? + void send(HalEventConfig eventConfig, HalEventData eventData); /** * @return the number of registered objects diff --git a/src/se/hal/intf/HalEventReportListener.java b/src/se/hal/intf/HalEventReportListener.java index 0f599e75..d46e7bf3 100755 --- a/src/se/hal/intf/HalEventReportListener.java +++ b/src/se/hal/intf/HalEventReportListener.java @@ -2,6 +2,6 @@ package se.hal.intf; public interface HalEventReportListener { - void reportReceived(HalEventConfig e, HalEventData d); + void reportReceived(HalEventConfig e, HalDeviceData d); } \ No newline at end of file diff --git a/src/se/hal/intf/HalSensorReportListener.java b/src/se/hal/intf/HalSensorReportListener.java index 97deef92..7e48510b 100755 --- a/src/se/hal/intf/HalSensorReportListener.java +++ b/src/se/hal/intf/HalSensorReportListener.java @@ -2,6 +2,6 @@ package se.hal.intf; public interface HalSensorReportListener { - void reportReceived(HalSensorConfig s, HalSensorData d); + void reportReceived(HalSensorConfig s, HalDeviceData d); } \ No newline at end of file diff --git a/src/se/hal/plugin/tellstick/TellstickDevice.java b/src/se/hal/plugin/tellstick/TellstickDevice.java new file mode 100755 index 00000000..72a92f6d --- /dev/null +++ b/src/se/hal/plugin/tellstick/TellstickDevice.java @@ -0,0 +1,13 @@ +package se.hal.plugin.tellstick; + +/** + * This interface represents a device configuration and links it to a protocol. + * + * Created by Ziver on 2016-08-18. + */ +public interface TellstickDevice { + + + String getProtocolName(); // TODO: could be implemented in a better way + String getModelName(); // TODO: could be implemented in a better way +} diff --git a/src/se/hal/plugin/tellstick/TellstickGroupProtocol.java b/src/se/hal/plugin/tellstick/TellstickDeviceGroup.java similarity index 81% rename from src/se/hal/plugin/tellstick/TellstickGroupProtocol.java rename to src/se/hal/plugin/tellstick/TellstickDeviceGroup.java index fcda24a9..ae278379 100755 --- a/src/se/hal/plugin/tellstick/TellstickGroupProtocol.java +++ b/src/se/hal/plugin/tellstick/TellstickDeviceGroup.java @@ -28,16 +28,11 @@ package se.hal.plugin.tellstick; * Indicates that the implementing class is a protocol that can have group events. * More specifically that on transmission will affect multiple devices. */ -public interface TellstickGroupProtocol { +public interface TellstickDeviceGroup { /** * Protocols should extend this method if it has group functionality. - * @return true if this object an the input is in the same group. + * @return true if this object and the input object belongs to the same group. */ - public boolean equalsGroup(TellstickGroupProtocol obj); - - /** - * Copy the state data from the group to this object. - */ - public void copyGroupData(TellstickGroupProtocol groupProtocol); + public boolean equalsGroup(TellstickDeviceGroup obj); } diff --git a/src/se/hal/plugin/tellstick/TellstickParser.java b/src/se/hal/plugin/tellstick/TellstickParser.java index 80c0a6fb..78fc902d 100755 --- a/src/se/hal/plugin/tellstick/TellstickParser.java +++ b/src/se/hal/plugin/tellstick/TellstickParser.java @@ -22,12 +22,15 @@ package se.hal.plugin.tellstick; +import se.hal.plugin.tellstick.TellstickProtocol.TellstickDecodedEntry; import se.hal.plugin.tellstick.protocol.NexaSelfLearningProtocol; import se.hal.plugin.tellstick.protocol.Oregon0x1A2DProtocol; import zutil.converter.Converter; import zutil.log.LogUtil; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -38,7 +41,7 @@ import java.util.logging.Logger; */ public class TellstickParser { private static final Logger logger = LogUtil.getLogger(); - private static HashMap> protocolMap; + private static HashMap protocolMap; static { registerProtocol(NexaSelfLearningProtocol.class); @@ -48,8 +51,12 @@ public class TellstickParser { private int firmwareVersion = -1; - - public TellstickProtocol decode(String data) { + /** + * Will decode the given data and return a list with device and data objects + * @param data + * @return a list with decoded objects or empty list if there was an error + */ + public List decode(String data) { if (data.startsWith("+W")) { data = data.substring(2); HashMap map = new HashMap(); @@ -59,19 +66,16 @@ public class TellstickParser { map.put(keyValue[0], keyValue[1]); } - Class protClass = - getProtocolClass(map.get("protocol"), map.get("model")); - if (protClass != null) { - try { - TellstickProtocol protocol = protClass.newInstance(); - String binData = map.get("data"); + TellstickProtocol protocol = + getProtocolInstance(map.get("protocol"), map.get("model")); + if (protocol != null) { + String binData = map.get("data"); - protocol.decode(Converter.hexToByte(binData)); - logger.finest("Decoded: " + protocol); - return protocol; - } catch (Exception e) { - logger.log(Level.WARNING, null, e); - } + logger.finest("Decoding: " + protocol); + List list = protocol.decode(Converter.hexToByte(binData)); + if (list == null) + list = Collections.EMPTY_LIST; + return list; } else { logger.warning("Unknown protocol: " + data); } @@ -87,9 +91,12 @@ public class TellstickParser { logger.severe("Unknown prefix: " + data); } - return null; + return Collections.EMPTY_LIST; } + /** + * This method blocks until a send command confirmation is received. + */ public void waitSendConformation(){ try { this.wait(); @@ -104,20 +111,23 @@ public class TellstickParser { } + public static void registerProtocol(Class protClass) { try { - if (protocolMap == null) - protocolMap = new HashMap<>(); - TellstickProtocol tmp = protClass.newInstance(); - protocolMap.put( - tmp.getProtocolName() + "-" + tmp.getModelName(), - protClass); + registerProtocol( protClass.newInstance() ); } catch (Exception e) { logger.log(Level.SEVERE, null, e); } } + public static void registerProtocol(TellstickProtocol protObj) { + if (protocolMap == null) + protocolMap = new HashMap<>(); + protocolMap.put( + protObj.getProtocolName() + "-" + protObj.getModelName(), + protObj); + } - public static Class getProtocolClass(String protocol, String model) { + public static TellstickProtocol getProtocolInstance(String protocol, String model) { return protocolMap.get(protocol + "-" + model); } } diff --git a/src/se/hal/plugin/tellstick/TellstickProtocol.java b/src/se/hal/plugin/tellstick/TellstickProtocol.java index 37020880..deb3c904 100755 --- a/src/se/hal/plugin/tellstick/TellstickProtocol.java +++ b/src/se/hal/plugin/tellstick/TellstickProtocol.java @@ -21,9 +21,12 @@ */ package se.hal.plugin.tellstick; +import se.hal.intf.HalDeviceData; import se.hal.intf.HalEventConfig; import se.hal.intf.HalEventData; +import java.util.List; + /** * Created by Ziver on 2015-02-18. */ @@ -47,6 +50,24 @@ public abstract class TellstickProtocol { } public String encode(HalEventConfig deviceConfig, HalEventData deviceData){ return null; } - public abstract void decode(byte[] data); + public abstract List decode(byte[] data); + + + public static class TellstickDecodedEntry { + private TellstickDevice device; + private HalDeviceData data; + + public TellstickDecodedEntry(TellstickDevice device, HalDeviceData data){ + this.device = device; + this.data = data; + } + + public TellstickDevice getDevice(){ + return device; + } + public HalDeviceData getData(){ + return data; + } + } } diff --git a/src/se/hal/plugin/tellstick/TellstickSerialComm.java b/src/se/hal/plugin/tellstick/TellstickSerialComm.java index 669d7dca..872a8f9a 100755 --- a/src/se/hal/plugin/tellstick/TellstickSerialComm.java +++ b/src/se/hal/plugin/tellstick/TellstickSerialComm.java @@ -25,6 +25,7 @@ package se.hal.plugin.tellstick; import com.fazecast.jSerialComm.SerialPort; import se.hal.HalContext; import se.hal.intf.*; +import se.hal.plugin.tellstick.TellstickProtocol.TellstickDecodedEntry; import zutil.log.LogUtil; import zutil.struct.TimedHashSet; @@ -51,20 +52,20 @@ public class TellstickSerialComm implements Runnable, private SerialPort serial; private InputStream in; private OutputStream out; - private TimedHashSet set; // To check for duplicate transmissions + private TimedHashSet set; // To check for duplicate transmissions protected TellstickParser parser; private HalSensorReportListener sensorListener; private HalEventReportListener eventListener; - private List registeredDevices; + private List registeredDevices; public TellstickSerialComm() { - set = new TimedHashSet(TRANSMISSION_UNIQUENESS_TTL); + set = new TimedHashSet<>(TRANSMISSION_UNIQUENESS_TTL); parser = new TellstickParser(); - registeredDevices = Collections.synchronizedList(new ArrayList()); + registeredDevices = Collections.synchronizedList(new ArrayList()); } @Override @@ -122,21 +123,17 @@ public class TellstickSerialComm implements Runnable, logger.log(Level.SEVERE, null, e); } } - private void reportEvent(TellstickProtocol protocol){ - if (sensorListener != null && protocol instanceof HalSensorConfig) - sensorListener.reportReceived((HalSensorConfig) protocol); - else if (eventListener != null && protocol instanceof HalEventConfig) - eventListener.reportReceived((HalEventConfig) protocol); - } /** * There seems to be an issue with read(...) methods, only read() is working */ private String readLine() throws IOException { StringBuilder str = new StringBuilder(50); - char c = 0; - while((c = (char)in.read()) >= 0){ + int c; + while((c = in.read()) >= 0){ switch(c) { + case -1: + return null; case '\n': case '\r': if(str.length() > 0) @@ -149,48 +146,58 @@ public class TellstickSerialComm implements Runnable, return str.toString(); } protected void handleLine(String data){ - TellstickProtocol protocol = parser.decode(data); - if(protocol != null) { - if (protocol.getTimestamp() < 0) - protocol.setTimestamp(System.currentTimeMillis()); + List decodeList = parser.decode(data); + for (TellstickDecodedEntry entry : decodeList) { + if (entry.getData().getTimestamp() < 0) + entry.getData().setTimestamp(System.currentTimeMillis()); - boolean registered = registeredDevices.contains(protocol); - if(registered && !set.contains(data) || // check for duplicates transmissions of registered devices + 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 //Check for registered device that are in the same group - if(protocol instanceof TellstickGroupProtocol) { - TellstickGroupProtocol groupProtocol = (TellstickGroupProtocol) protocol; - for (int i=0; i getEventController() { return TellstickSerialComm.class; } + + @Override + public String getProtocolName() { return NexaSelfLearningProtocol.PROTOCOL; } + @Override + public String getModelName() { return NexaSelfLearningProtocol.MODEL; } } diff --git a/src/se/hal/plugin/tellstick/device/Oregon0x1A2D.java b/src/se/hal/plugin/tellstick/device/Oregon0x1A2D.java index 87f115ac..db2bbabb 100755 --- a/src/se/hal/plugin/tellstick/device/Oregon0x1A2D.java +++ b/src/se/hal/plugin/tellstick/device/Oregon0x1A2D.java @@ -3,8 +3,10 @@ package se.hal.plugin.tellstick.device; import se.hal.intf.HalEventController; import se.hal.intf.HalSensorConfig; import se.hal.intf.HalSensorController; +import se.hal.plugin.tellstick.TellstickDevice; import se.hal.plugin.tellstick.TellstickProtocol; import se.hal.plugin.tellstick.TellstickSerialComm; +import se.hal.plugin.tellstick.protocol.Oregon0x1A2DProtocol; import zutil.log.LogUtil; import zutil.ui.Configurator; @@ -13,7 +15,7 @@ import java.util.logging.Logger; /** * Created by Ziver on 2015-11-19. */ -public class Oregon0x1A2D implements HalSensorConfig { +public class Oregon0x1A2D implements HalSensorConfig,TellstickDevice { private static final Logger logger = LogUtil.getLogger(); @Configurator.Configurable("Address") @@ -23,6 +25,11 @@ public class Oregon0x1A2D implements HalSensorConfig { + public Oregon0x1A2D() { } + public Oregon0x1A2D(int address) { + this.address = address; + } + @Override public boolean equals(Object obj){ @@ -52,4 +59,9 @@ public class Oregon0x1A2D implements HalSensorConfig { return TellstickSerialComm.class; } + + @Override + public String getProtocolName() { return Oregon0x1A2DProtocol.PROTOCOL; } + @Override + public String getModelName() { return Oregon0x1A2DProtocol.MODEL; } } diff --git a/src/se/hal/plugin/tellstick/protocol/NexaSelfLearningProtocol.java b/src/se/hal/plugin/tellstick/protocol/NexaSelfLearningProtocol.java index 0888be67..a481e15e 100755 --- a/src/se/hal/plugin/tellstick/protocol/NexaSelfLearningProtocol.java +++ b/src/se/hal/plugin/tellstick/protocol/NexaSelfLearningProtocol.java @@ -23,29 +23,66 @@ package se.hal.plugin.tellstick.protocol; import se.hal.intf.HalEventConfig; -import se.hal.plugin.tellstick.TellstickGroupProtocol; +import se.hal.intf.HalEventData; import se.hal.plugin.tellstick.TellstickProtocol; +import se.hal.plugin.tellstick.device.NexaSelfLearning; +import se.hal.struct.devicedata.SwitchEventData; import zutil.ByteUtil; +import zutil.log.LogUtil; import zutil.parser.binary.BinaryStruct; import zutil.parser.binary.BinaryStructInputStream; import zutil.parser.binary.BinaryStructOutputStream; -import zutil.ui.Configurator; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Created by Ziver on 2015-02-18. */ public class NexaSelfLearningProtocol extends TellstickProtocol { + private static final Logger logger = LogUtil.getLogger(); + public static final String PROTOCOL = "arctech"; + public static final String MODEL = "selflearning"; + private static class NexaSLTransmissionStruct implements BinaryStruct{ + @BinaryField(index=1, length=26) + int house = 0; + + @BinaryField(index=2, length=1) + boolean group = false; + + @BinaryField(index=3, length=1) + boolean enable = false; + + @BinaryField(index=4, length=4) + int unit = 0; + } + public NexaSelfLearningProtocol() { - super("arctech", "selflearning"); + super(PROTOCOL, MODEL); } @Override - public String encode(){ + public String encode(HalEventConfig deviceConfig, HalEventData deviceData){ + if ( ! (deviceConfig instanceof NexaSelfLearning)){ + logger.severe("Device config is not instance of NexaSelfLearning: "+deviceConfig.getClass()); + return null; + } + if ( ! (deviceData instanceof SwitchEventData)){ + logger.severe("Device data is not instance of SwitchEventData: "+deviceData.getClass()); + return null; + } + NexaSLTransmissionStruct struct = new NexaSLTransmissionStruct(); + struct.house = ((NexaSelfLearning) deviceConfig).getHouse(); + struct.group = ((NexaSelfLearning) deviceConfig).getGroup(); + struct.enable = ((SwitchEventData) deviceData).isOn(); + struct.unit = ((NexaSelfLearning) deviceConfig).getUnit(); + try { // T[t0][t1][t2][t3][length][d1]..[dn]+ StringBuilder enc = new StringBuilder(90); // Tellstick supports max 74 bytes @@ -54,7 +91,7 @@ public class NexaSelfLearningProtocol extends TellstickProtocol { enc.append((char)0b0000_1001); // preamble int length = 4; - byte[] data = BinaryStructOutputStream.serialize(this); + byte[] data = BinaryStructOutputStream.serialize(struct); for (byte b : data){ for (int i=7; i>=0; --i){ if (ByteUtil.getBits(b, i, 1) == 0) @@ -70,15 +107,16 @@ public class NexaSelfLearningProtocol extends TellstickProtocol { enc.append("+"); return enc.toString(); + } catch (IOException e) { - e.printStackTrace(); + logger.log(Level.SEVERE, null, e); } - return ""; + return null; } @Override - public void decode(byte[] data){ + public List decode(byte[] data){ // Data positions // house = 0xFFFFFFC0 // group = 0x00000020 @@ -88,7 +126,15 @@ public class NexaSelfLearningProtocol extends TellstickProtocol { // 0x2CE81990 - 00101100_11101000_00011001_10 0 1 0000 - ON // 0x2CE81980 - 00101100_11101000_00011001_10 0 0 0000 - OFF - BinaryStructInputStream.read(this, data); + NexaSLTransmissionStruct struct = new NexaSLTransmissionStruct(); + BinaryStructInputStream.read(struct, data); + + ArrayList list = new ArrayList<>(); + list.add(new TellstickDecodedEntry( + new NexaSelfLearning(struct.house, struct.group, struct.unit), + new SwitchEventData(struct.enable) + )); + return list; } diff --git a/src/se/hal/plugin/tellstick/protocol/Oregon0x1A2DProtocol.java b/src/se/hal/plugin/tellstick/protocol/Oregon0x1A2DProtocol.java index e2e9cd18..19ff566f 100755 --- a/src/se/hal/plugin/tellstick/protocol/Oregon0x1A2DProtocol.java +++ b/src/se/hal/plugin/tellstick/protocol/Oregon0x1A2DProtocol.java @@ -1,10 +1,13 @@ package se.hal.plugin.tellstick.protocol; -import se.hal.intf.HalSensorConfig; import se.hal.plugin.tellstick.TellstickProtocol; +import se.hal.plugin.tellstick.device.Oregon0x1A2D; +import se.hal.struct.devicedata.HumiditySensorData; +import se.hal.struct.devicedata.TemperatureSensorData; import zutil.log.LogUtil; -import zutil.ui.Configurator; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Logger; /** @@ -12,20 +15,22 @@ import java.util.logging.Logger; */ public class Oregon0x1A2DProtocol extends TellstickProtocol { private static final Logger logger = LogUtil.getLogger(); + public static final String PROTOCOL = "oregon"; + public static final String MODEL = "0x1A2D"; public Oregon0x1A2DProtocol(){ - super("oregon", "0x1A2D"); + super(PROTOCOL, MODEL); } @Override - public void decode(byte[] data) { + public List decode(byte[] data) { //class:sensor;protocol:oregon;model:0x1A2D;data:20BA000000002700; // int channel = (data[0] >> 4) & 0x7; // channel not used - address = data[1] & 0xFF; + int address = data[1] & 0xFF; int temp3 = (data[2] >> 4) & 0xF; int temp1 = (data[3] >> 4) & 0xF; int temp2 = data[3] & 0xF; @@ -44,14 +49,24 @@ public class Oregon0x1A2DProtocol extends TellstickProtocol { if (calcChecksum != checksum) { logger.fine("Checksum failed, address: "+address); - return; + return null; } - temperature = ((temp1 * 100) + (temp2 * 10) + temp3)/10.0; + double temperature = ((temp1 * 100) + (temp2 * 10) + temp3)/10.0; if (negative) temperature = -temperature; - humidity = (hum1 * 10.0) + hum2; + double humidity = (hum1 * 10.0) + hum2; + // Create return objects + ArrayList list = new ArrayList<>(); + Oregon0x1A2D device = new Oregon0x1A2D(address); + list.add(new TellstickDecodedEntry( + device, new TemperatureSensorData(temperature) + )); + list.add(new TellstickDecodedEntry( + device, new HumiditySensorData(humidity) + )); + return list; } } diff --git a/src/se/hal/struct/devicedata/HumiditySensorData.java b/src/se/hal/struct/devicedata/HumiditySensorData.java index 32e37f95..5c224427 100755 --- a/src/se/hal/struct/devicedata/HumiditySensorData.java +++ b/src/se/hal/struct/devicedata/HumiditySensorData.java @@ -11,6 +11,12 @@ public class HumiditySensorData extends HalSensorData { private double humidity; + public HumiditySensorData() { } + public HumiditySensorData(double humidity) { + this.humidity = humidity; + } + + @Override public double getData() { return humidity; diff --git a/src/se/hal/struct/devicedata/SwitchEventData.java b/src/se/hal/struct/devicedata/SwitchEventData.java index 3ce2b819..bbdbae1b 100755 --- a/src/se/hal/struct/devicedata/SwitchEventData.java +++ b/src/se/hal/struct/devicedata/SwitchEventData.java @@ -32,6 +32,11 @@ public class SwitchEventData extends HalEventData { private boolean enabled; + public SwitchEventData() { } + public SwitchEventData(boolean enabled) { + this.enabled = enabled; + } + public void turnOn(){ enabled = true; } diff --git a/src/se/hal/struct/devicedata/TemperatureSensorData.java b/src/se/hal/struct/devicedata/TemperatureSensorData.java index 024191c9..7bc31799 100755 --- a/src/se/hal/struct/devicedata/TemperatureSensorData.java +++ b/src/se/hal/struct/devicedata/TemperatureSensorData.java @@ -10,6 +10,11 @@ public class TemperatureSensorData extends HalSensorData { private double temperature; + public TemperatureSensorData(){} + public TemperatureSensorData(double temperature){ + this.temperature = temperature; + } + /** * @param data the temperature to set in degrees C */ diff --git a/test/se/hal/plugin/tellstick/protocol/NexaSelfLearningTest.java b/test/se/hal/plugin/tellstick/protocol/NexaSelfLearningTest.java index 072ee09a..54362024 100755 --- a/test/se/hal/plugin/tellstick/protocol/NexaSelfLearningTest.java +++ b/test/se/hal/plugin/tellstick/protocol/NexaSelfLearningTest.java @@ -22,9 +22,14 @@ 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.struct.devicedata.SwitchEventData; import zutil.converter.Converter; import java.nio.charset.StandardCharsets; +import java.util.List; import static org.junit.Assert.*; @@ -32,10 +37,11 @@ public class NexaSelfLearningTest { @org.junit.Test public void testEncode() throws Exception { - NexaSelfLearningProtocol nexa = new NexaSelfLearningProtocol(); - nexa.setHouse(11_772_006); - nexa.setUnit(0); - nexa.turnOn(); + NexaSelfLearning nexaDevice = new NexaSelfLearning(); + nexaDevice.setHouse(11_772_006); + nexaDevice.setUnit(0); + SwitchEventData nexaData = new SwitchEventData(); + nexaData.turnOn(); byte[] expected = Converter.toBytes(new char[]{ 84, // T @@ -50,7 +56,8 @@ public class NexaSelfLearningTest { 0x00, // postemble 43}); // + - byte[] actual = nexa.encode().getBytes(StandardCharsets.ISO_8859_1); + NexaSelfLearningProtocol nexaProt = new NexaSelfLearningProtocol(); + byte[] actual = nexaProt.encode(nexaDevice, nexaData).getBytes(StandardCharsets.ISO_8859_1); System.out.println("Expected: "+Converter.toHexString(expected).toUpperCase()); System.out.println("Actual : "+Converter.toHexString(actual).toUpperCase()); @@ -60,25 +67,25 @@ public class NexaSelfLearningTest { @org.junit.Test public void decode_ON() throws Exception { - NexaSelfLearningProtocol nexa = decode("0x2CE81990"); + TellstickDecodedEntry nexa = decode("0x2CE81990"); - assertEquals("House Code", 11772006, nexa.getHouse()); - assertEquals("Unit Code", 0, nexa.getUnit()); - assertTrue("Enabled", nexa.isOn()); + assertEquals("House Code", 11772006, ((NexaSelfLearning)nexa.getDevice()).getHouse()); + assertEquals("Unit Code", 0, ((NexaSelfLearning)nexa.getDevice()).getUnit()); + assertTrue("Enabled", ((SwitchEventData)nexa.getData()).isOn()); } @org.junit.Test public void decode_OFF() throws Exception { - NexaSelfLearningProtocol nexa = decode("0x2CE81980"); + TellstickDecodedEntry nexa = decode("0x2CE81980"); - assertEquals("House Code", 11772006, nexa.getHouse()); - assertEquals("Unit Code", 0, nexa.getUnit()); - assertFalse("Enabled", nexa.isOn()); + assertEquals("House Code", 11772006, ((NexaSelfLearning)nexa.getDevice()).getHouse()); + assertEquals("Unit Code", 0, ((NexaSelfLearning)nexa.getDevice()).getUnit()); + assertFalse("Enabled", ((SwitchEventData)nexa.getData()).isOn()); } - private NexaSelfLearningProtocol decode(String data){ - NexaSelfLearningProtocol nexa = new NexaSelfLearningProtocol(); - nexa.decode(Converter.hexToByte(data)); - return nexa; + private TellstickDecodedEntry decode(String data){ + NexaSelfLearningProtocol nexaProt = new NexaSelfLearningProtocol(); + List list = nexaProt.decode(Converter.hexToByte(data)); + return list.get(0); } } \ No newline at end of file