Fixed isse where group data was not copied for group events in Nexa. issue 12
This commit is contained in:
parent
8ca169a2ab
commit
f670d2ceb4
4 changed files with 68 additions and 14 deletions
46
src/se/hal/plugin/tellstick/TellstickGroupProtocol.java
Executable file
46
src/se/hal/plugin/tellstick/TellstickGroupProtocol.java
Executable file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -66,11 +66,6 @@ public abstract class TellstickProtocol {
|
||||||
public abstract String encode();
|
public abstract String encode();
|
||||||
public abstract void decode(byte[] data);
|
public abstract void decode(byte[] data);
|
||||||
|
|
||||||
/**
|
public abstract boolean equals(Object obj);
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -131,9 +131,16 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
|
||||||
!registered && set.contains(data)) { // required duplicate transmissions before reporting unregistered devices
|
!registered && set.contains(data)) { // required duplicate transmissions before reporting unregistered devices
|
||||||
|
|
||||||
//Check for registered device that are in the same group
|
//Check for registered device that are in the same group
|
||||||
for (TellstickProtocol childProtocol : registeredDevices){
|
if(protocol instanceof TellstickGroupProtocol) {
|
||||||
if (protocol.equalsGroup(childProtocol) && !protocol.equals(childProtocol))
|
TellstickGroupProtocol groupProtocol = (TellstickGroupProtocol) protocol;
|
||||||
reportEvent(protocol);
|
for (TellstickProtocol childProtocol : registeredDevices) {
|
||||||
|
if (childProtocol instanceof TellstickGroupProtocol &&
|
||||||
|
groupProtocol.equalsGroup(childProtocol) &&
|
||||||
|
!protocol.equals(childProtocol)) {
|
||||||
|
((TellstickGroupProtocol) childProtocol).copyGroupData(groupProtocol);
|
||||||
|
reportEvent(childProtocol);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Report source event
|
// Report source event
|
||||||
reportEvent(protocol);
|
reportEvent(protocol);
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
package se.hal.plugin.tellstick.protocols;
|
package se.hal.plugin.tellstick.protocols;
|
||||||
|
|
||||||
|
import se.hal.plugin.tellstick.TellstickGroupProtocol;
|
||||||
import se.hal.plugin.tellstick.TellstickProtocol;
|
import se.hal.plugin.tellstick.TellstickProtocol;
|
||||||
import se.hal.struct.SwitchEventData;
|
import se.hal.struct.SwitchEventData;
|
||||||
import zutil.ui.Configurator;
|
import zutil.ui.Configurator;
|
||||||
|
|
@ -29,7 +30,7 @@ import zutil.ui.Configurator;
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-02-18.
|
* 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")
|
@Configurator.Configurable("House code")
|
||||||
private int house = 0;
|
private int house = 0;
|
||||||
|
|
@ -162,6 +163,7 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa
|
||||||
";method:"+enable;
|
";method:"+enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj){
|
public boolean equals(Object obj){
|
||||||
if(obj instanceof NexaSelfLearning)
|
if(obj instanceof NexaSelfLearning)
|
||||||
return ((NexaSelfLearning) obj).house == house &&
|
return ((NexaSelfLearning) obj).house == house &&
|
||||||
|
|
@ -169,17 +171,21 @@ public class NexaSelfLearning extends TellstickProtocol implements SwitchEventDa
|
||||||
((NexaSelfLearning)obj).unit == unit;
|
((NexaSelfLearning)obj).unit == unit;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public boolean equalsGroup(Object obj){
|
@Override
|
||||||
|
public boolean equalsGroup(TellstickProtocol obj) {
|
||||||
if(obj instanceof NexaSelfLearning)
|
if(obj instanceof NexaSelfLearning)
|
||||||
return ((NexaSelfLearning) obj).house == house &&
|
return ((NexaSelfLearning) obj).house == house &&
|
||||||
(((NexaSelfLearning) obj).group || group );
|
(((NexaSelfLearning) obj).group || group );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void copyGroupData(TellstickGroupProtocol group) {
|
||||||
|
if(group instanceof NexaSelfLearning)
|
||||||
|
this.enable = ((NexaSelfLearning) group).enable;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getData() {
|
public double getData() {
|
||||||
return (enable ? 1 : 0);
|
return (enable ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue