Split switch event data into multiple classes

This commit is contained in:
Ziver Koc 2021-01-02 04:25:04 +01:00
parent 4499824965
commit 6214c01157
23 changed files with 259 additions and 96 deletions

View file

@ -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

View file

@ -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;
/**

View file

@ -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;

View file

@ -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;

View file

@ -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) {

View file

@ -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

View file

@ -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){