From cf646bb340d233c1a08cc56499a93ff6142b14d8 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Mon, 15 Feb 2016 16:45:51 +0100 Subject: [PATCH] Fixed TC and initial implementation of Nexa group transmissions. issue 12 --- .../plugin/tellstick/TellstickProtocol.java | 8 ++++++ .../tellstick/protocols/NexaSelfLearning.java | 26 +++++++++++++------ .../TelstickSerialCommNexaOnOffTest.java | 2 +- .../protocols/NexaSelfLearningTest.java | 4 +-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/se/hal/plugin/tellstick/TellstickProtocol.java b/src/se/hal/plugin/tellstick/TellstickProtocol.java index 1880b30c..106f872a 100755 --- a/src/se/hal/plugin/tellstick/TellstickProtocol.java +++ b/src/se/hal/plugin/tellstick/TellstickProtocol.java @@ -65,4 +65,12 @@ public abstract class TellstickProtocol { public abstract String encode(); public abstract void decode(byte[] data); + + /** + * Protocols should extend this method if it has group functionality. + * @return true if this object an the input is in the same group. + */ + public boolean equalsGroup(Object obj){ + return false; + } } diff --git a/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java b/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java index 8359ca95..2e038f3b 100755 --- a/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java +++ b/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java @@ -34,7 +34,7 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa @Configurator.Configurable("House code") private int house = 0; @Configurator.Configurable("Group code") - private int group = 0; + private boolean group = false; @Configurator.Configurable("Unit code") private int unit = 0; @@ -47,6 +47,8 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa public String encode(){ + // Binary 0 => "01" + // Binary 1 => "10" StringBuilder enc = new StringBuilder(); enc.append(new char[]{'T', 127, 255, 24, 1}); @@ -58,7 +60,10 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa m.append( (house & (1 << i)) == 0 ? "01" : "10" ); } // Group - m.append("01"); + if (group) + m.append("10"); + else + m.append("01"); // On or OFF if (enable) @@ -89,7 +94,6 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa } } - enc.append("+"); return enc.toString(); } @@ -110,13 +114,12 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa house |= (data[1] & 0xFF) << 2; house |= (data[0] & 0xC0) >>> 6; - group = data[0] & 0x20; - group >>>= 5; + int tmpGroup = data[0] & 0x20; // >>> 5 + group = tmpGroup != 0; enable = (data[0] & 0x10) != 0; unit = data[0] & 0x0F; - //unit++; } @@ -126,10 +129,10 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa public void setHouse(int house) { this.house = house; } - public int getGroup() { + public boolean getGroup() { return group; } - public void setGroup(int group) { + public void setGroup(boolean group) { this.group = group; } public int getUnit() { @@ -162,9 +165,16 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa public boolean equals(Object obj){ if(obj instanceof NexaSelfLearning) return ((NexaSelfLearning) obj).house == house && + ((NexaSelfLearning) obj).group == group && ((NexaSelfLearning)obj).unit == unit; return false; } + public boolean equalsGroup(Object obj){ + if(obj instanceof NexaSelfLearning) + return ((NexaSelfLearning) obj).house == house && + (((NexaSelfLearning) obj).group || group ); + return false; + } @Override diff --git a/test/se/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java b/test/se/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java index a426a228..bff68ecb 100755 --- a/test/se/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java +++ b/test/se/hal/plugin/tellstick/TelstickSerialCommNexaOnOffTest.java @@ -20,7 +20,7 @@ public class TelstickSerialCommNexaOnOffTest { NexaSelfLearning nexa = new NexaSelfLearning(); //nexa.setHouse(11772006); nexa.setHouse(14160770); - nexa.setGroup(0); + nexa.setGroup(false); nexa.setUnit(1); System.out.println("Up and Running"); diff --git a/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java b/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java index ab65f637..57172c63 100755 --- a/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java +++ b/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java @@ -51,7 +51,7 @@ public class NexaSelfLearningTest { NexaSelfLearning nexa = decode("0x2CE81990"); assertEquals("House Code", 11772006, nexa.getHouse()); - assertEquals("Unit Code", 1, nexa.getUnit()); + assertEquals("Unit Code", 0, nexa.getUnit()); assertTrue("Enabled", nexa.isOn()); @@ -61,7 +61,7 @@ public class NexaSelfLearningTest { NexaSelfLearning nexa = decode("0x2CE81980"); assertEquals("House Code", 11772006, nexa.getHouse()); - assertEquals("Unit Code", 1, nexa.getUnit()); + assertEquals("Unit Code", 0, nexa.getUnit()); assertFalse("Enabled", nexa.isOn()); }