diff --git a/src/se/hal/plugin/tellstick/TellstickGroupProtocol.java b/src/se/hal/plugin/tellstick/TellstickGroupProtocol.java new file mode 100755 index 00000000..4b2ed0f7 --- /dev/null +++ b/src/se/hal/plugin/tellstick/TellstickGroupProtocol.java @@ -0,0 +1,46 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Ziver Koc + * + * 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.plugin.tellstick; + +import se.hal.intf.HalEventController; +import se.hal.intf.HalSensorController; + +/** + * 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 { + + /** + * 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(TellstickProtocol obj); + + /** + * Copy the state data from the group to this object. + */ + public void copyGroupData(TellstickGroupProtocol groupProtocol); +} diff --git a/src/se/hal/plugin/tellstick/TellstickProtocol.java b/src/se/hal/plugin/tellstick/TellstickProtocol.java index 106f872a..aeee9c3d 100755 --- a/src/se/hal/plugin/tellstick/TellstickProtocol.java +++ b/src/se/hal/plugin/tellstick/TellstickProtocol.java @@ -66,11 +66,6 @@ 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; - } + public abstract boolean equals(Object obj); + } diff --git a/src/se/hal/plugin/tellstick/TellstickSerialComm.java b/src/se/hal/plugin/tellstick/TellstickSerialComm.java index d785e700..35c5afbb 100755 --- a/src/se/hal/plugin/tellstick/TellstickSerialComm.java +++ b/src/se/hal/plugin/tellstick/TellstickSerialComm.java @@ -131,9 +131,16 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv !registered && set.contains(data)) { // required duplicate transmissions before reporting unregistered devices //Check for registered device that are in the same group - for (TellstickProtocol childProtocol : registeredDevices){ - if (protocol.equalsGroup(childProtocol) && !protocol.equals(childProtocol)) - reportEvent(protocol); + if(protocol instanceof TellstickGroupProtocol) { + TellstickGroupProtocol groupProtocol = (TellstickGroupProtocol) protocol; + for (TellstickProtocol childProtocol : registeredDevices) { + if (childProtocol instanceof TellstickGroupProtocol && + groupProtocol.equalsGroup(childProtocol) && + !protocol.equals(childProtocol)) { + ((TellstickGroupProtocol) childProtocol).copyGroupData(groupProtocol); + reportEvent(childProtocol); + } + } } // Report source event reportEvent(protocol); diff --git a/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java b/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java index 2e038f3b..5917d182 100755 --- a/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java +++ b/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java @@ -22,6 +22,7 @@ package se.hal.plugin.tellstick.protocols; +import se.hal.plugin.tellstick.TellstickGroupProtocol; import se.hal.plugin.tellstick.TellstickProtocol; import se.hal.struct.SwitchEventData; import zutil.ui.Configurator; @@ -29,7 +30,7 @@ import zutil.ui.Configurator; /** * Created by Ziver on 2015-02-18. */ -public class NexaSelfLearning extends TellstickProtocol implements SwitchEventData { +public class NexaSelfLearning extends TellstickProtocol implements SwitchEventData,TellstickGroupProtocol { @Configurator.Configurable("House code") private int house = 0; @@ -162,6 +163,7 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa ";method:"+enable; } + @Override public boolean equals(Object obj){ if(obj instanceof NexaSelfLearning) return ((NexaSelfLearning) obj).house == house && @@ -169,17 +171,21 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa ((NexaSelfLearning)obj).unit == unit; return false; } - public boolean equalsGroup(Object obj){ + @Override + public boolean equalsGroup(TellstickProtocol obj) { if(obj instanceof NexaSelfLearning) return ((NexaSelfLearning) obj).house == house && (((NexaSelfLearning) obj).group || group ); return false; } - + @Override + public void copyGroupData(TellstickGroupProtocol group) { + if(group instanceof NexaSelfLearning) + this.enable = ((NexaSelfLearning) group).enable; + } @Override public double getData() { return (enable ? 1 : 0); } - }