Mooved Tellstick plugin to plugin folder and added all targets to build xml

This commit is contained in:
Ziver Koc 2017-05-29 17:02:31 +02:00
parent efdbc56859
commit da290e570f
25 changed files with 155 additions and 11 deletions

View file

@ -6,7 +6,7 @@ import org.junit.Before;
import org.junit.Test;
import se.hal.HalContext;
import se.hal.plugin.tellstick.device.Oregon0x1A2D;
import se.hal.plugin.netscan.NetworkDevice;
import se.hal.util.UTCTimeUtility;
import zutil.db.DBConnection;
import zutil.db.DBUpgradeHandler;
@ -43,7 +43,7 @@ public class SensorDataAggregationDeamonTest {
System.out.println("Adding user to database");
db.exec("INSERT INTO user(id, external, username) VALUES(222, 0, 'test')"); //adding user
System.out.println("Adding sensor to database");
db.exec("INSERT INTO sensor(id, user_id, external_id, type) VALUES(111, 222, 333, '"+Oregon0x1A2D.class.getName()+"')"); //adding sensor
db.exec("INSERT INTO sensor(id, user_id, external_id, type) VALUES(111, 222, 333, '"+NetworkDevice.class.getName()+"')"); //adding sensor
System.out.println("Generating raw data and saving it to the database...");
PreparedStatement stmt = db.getPreparedStatement("INSERT INTO sensor_data_raw (timestamp, sensor_id, data) VALUES(?, ?, ?)");
try{
@ -77,7 +77,7 @@ public class SensorDataAggregationDeamonTest {
//TODO: verify the aggregation
System.out.println("Finnished testing raw data aggregation");
System.out.println("Finished testing raw data aggregation");
}

View file

@ -1,115 +0,0 @@
package se.hal.plugin.tellstick;
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;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* Created by Ziver on 2015-11-19.
*/
public class TelstickSerialCommEventTest {
@Before
public void init(){
TellstickParser.registerProtocol(TestEvent.class);
}
//############# Non crashing TC
@Test
public void startup(){
TellstickSerialComm tellstick = new TellstickSerialComm();
tellstick.handleLine("+V2");
}
@Test
public void unregisteredListener(){
TellstickSerialComm tellstick = new TellstickSerialComm();
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:1234;");
}
//############ Normal TCs
@Test
public void receiveUnregisteredEvent(){
// Setup
TellstickSerialComm tellstick = new TellstickSerialComm();
final ArrayList<HalEventConfig> list = new ArrayList<>();
tellstick.setListener(new HalEventReportListener() {
@Override
public void reportReceived(HalEventConfig e, HalEventData d) {
list.add(e);
}
});
// Execution
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
assertEquals("Events first transmission", 0, list.size());
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
assertEquals("Events Second transmission", 1, list.size());
}
@Test
public void receiveEvent(){
// Setup
TellstickSerialComm tellstick = new TellstickSerialComm();
final ArrayList<HalEventConfig> list = new ArrayList<>();
tellstick.setListener(new HalEventReportListener() {
@Override
public void reportReceived(HalEventConfig e, HalEventData d) {
list.add(e);
}
});
// Execution
TestEvent event = new TestEvent();
event.testData = 0xAAAA;
tellstick.register(event);
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:AAAA;");
// Verification
assertEquals("Nr of received events", 1, list.size());
assertEquals("Data", event.testData, ((TestEvent)list.get(0)).testData);
}
private static class TestEvent extends TellstickProtocol implements HalEventConfig,TellstickDevice {
public int testData;
public TestEvent(){
super("test-prot", "test-model");
}
@Override
public List<TellstickDecodedEntry> decode(byte[] data) {
testData = Converter.toInt(data);
ArrayList<TellstickDecodedEntry> list = new ArrayList<>();
list.add(new TellstickDecodedEntry(
this, new DimmerEventData(testData, System.currentTimeMillis())
));
return list;
}
@Override
public Class<? extends HalEventController> getEventControllerClass() { return null; }
@Override
public Class<? extends HalEventData> getEventDataClass() {
return null;
}
@Override
public boolean equals(Object obj) {return testData == ((TestEvent)obj).testData;}
}
}

View file

@ -1,53 +0,0 @@
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;
/**
* Created by Ziver on 2015-11-19.
*/
public class TelstickSerialCommNexaOnOffTest {
public static void main(String[] args) {
try {
System.out.println("Connecting to db...");
TellstickSerialComm comm = new TellstickSerialComm();
// http://developer.telldus.com/doxygen/TellStick.html
comm.initialize("COM8");
//comm.connect("/dev/ttyUSB1");
Thread.sleep(1000);
NexaSelfLearning nexaDevice = new NexaSelfLearning();
//nexa.setHouse(11772006);
nexaDevice.setHouse(14160770);
nexaDevice.setGroup(false);
nexaDevice.setUnit(1);
SwitchEventData nexaData = new SwitchEventData();
System.out.println("Up and Running");
while(true) {
Thread.sleep(2000);
nexaData.turnOn();
nexaDevice.setUnit(0);
comm.send(nexaDevice, nexaData);
Thread.sleep(2000);
nexaDevice.setUnit(1);
comm.send(nexaDevice, nexaData);
Thread.sleep(2000);
nexaData.turnOff();
nexaDevice.setUnit(0);
comm.send(nexaDevice, nexaData);
Thread.sleep(2000);
nexaDevice.setUnit(1);
comm.send(nexaDevice, nexaData);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -1,104 +0,0 @@
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;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* Created by Ziver on 2015-11-19.
*/
public class TelstickSerialCommSensorTest {
@Before
public void init(){
TellstickParser.registerProtocol(TestSensor.class);
}
//############ Normal TCs
@Test
public void receiveUnregisteredSensor(){
// Setup
TellstickSerialComm tellstick = new TellstickSerialComm();
final ArrayList<HalSensorConfig> list = new ArrayList<>();
tellstick.setListener(new HalSensorReportListener() {
@Override
public void reportReceived(HalSensorConfig e, HalSensorData d) {
list.add(e);
}
});
// Execution
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
assertEquals("Sensors first transmission", 0, list.size());
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
assertEquals("Sensors Second transmission", 1, list.size());
}
@Test
public void receiveSensor(){
// Setup
TellstickSerialComm tellstick = new TellstickSerialComm();
final ArrayList<HalSensorConfig> list = new ArrayList<>();
tellstick.setListener(new HalSensorReportListener() {
@Override
public void reportReceived(HalSensorConfig e, HalSensorData d) {
list.add(e);
}
});
// Execution
TestSensor sensor = new TestSensor();
sensor.testData = 0xAAAA;
tellstick.register(sensor);
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:AAAA;");
// Verification
assertEquals("Nr of received sensors", 1, list.size());
assertEquals("Data", sensor.testData, ((TestSensor)list.get(0)).testData);
}
private static class TestSensor extends TellstickProtocol implements HalSensorConfig,TellstickDevice {
public int testData;
public TestSensor(){
super("test-prot", "test-model");
}
@Override
public List<TellstickDecodedEntry> decode(byte[] data) {
testData = Converter.toInt(data);
ArrayList<TellstickDecodedEntry> list = new ArrayList<>();
list.add(new TellstickDecodedEntry(
this, new TemperatureSensorData(testData, 0)
));
return list;
}
@Override
public boolean equals(Object obj) {return testData == ((TestSensor)obj).testData;}
@Override
public long getDataInterval() { return 0; }
@Override
public AggregationMethod getAggregationMethod() { return null; }
@Override
public Class<? extends HalSensorController> getSensorControllerClass() { return null; }
@Override
public Class<? extends HalSensorData> getSensorDataClass() {
return null;
}
}
}

View file

@ -1,119 +0,0 @@
/*
* Copyright (c) 2015 Ziver
*
* 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.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 zutil.converter.Converter;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static org.junit.Assert.*;
public class NexaSelfLearningTest {
@org.junit.Test
public void testSwitchEncode() throws Exception {
NexaSelfLearning nexaDevice = new NexaSelfLearning();
nexaDevice.setHouse(11_772_006);
nexaDevice.setUnit(3);
SwitchEventData nexaData = new SwitchEventData(true, System.currentTimeMillis());
byte[] expected = Converter.toBytes(new char[]{
84, // T
127, 255, 24, 0, // timings
132, // length
154, 138, 136, 170, 136, 168, 170, 138, 136, 168,
168, 170, 136, 170, 138, 138, 138, 138, 138, 136,
168, 170, 138, 136, 168, 170, 138, 136, 170, 138,
136, 168, 170,
43}); // +
NexaSelfLearningProtocol nexaProt = new NexaSelfLearningProtocol();
byte[] actual = nexaProt.encode(nexaDevice, nexaData).getTransmissionString()
.getBytes(StandardCharsets.ISO_8859_1);
System.out.println("Expected: "+Converter.toHexString(expected).toUpperCase());
System.out.println("Actual : "+Converter.toHexString(actual).toUpperCase());
assertArrayEquals(expected, actual);
}
@org.junit.Test
public void testDimmerEncode() throws Exception {
NexaSelfLearningDimmer nexaDevice = new NexaSelfLearningDimmer();
nexaDevice.setHouse(11_772_006);
nexaDevice.setUnit(3);
DimmerEventData nexaData = new DimmerEventData(0.5, System.currentTimeMillis());
byte[] expected = Converter.toBytes(new char[]{
84, // T
127, 255, 24, 0, // timings
164, // length, 32 extra timings
154, 138, 136, 170, 136, 168, 170, 138, 136, 168,
168, 170, 136, 170, 138, 138, 138, 138, 138, 136,
168, 170, 138, 136, 168, 170, 138,
138, 138, 138, 136, 168,
168, 170, 138, 138, 138, 138, 138, 138, 138, // Dimer value
43}); // +
NexaSelfLearningProtocol nexaProt = new NexaSelfLearningProtocol();
byte[] actual = nexaProt.encode(nexaDevice, nexaData).getTransmissionString()
.getBytes(StandardCharsets.ISO_8859_1);
System.out.println("Expected: "+Converter.toHexString(expected).toUpperCase());
System.out.println("Actual : "+Converter.toHexString(actual).toUpperCase());
assertArrayEquals(expected, actual);
}
@org.junit.Test
public void decode_ON() throws Exception {
TellstickDecodedEntry nexa = decode("0x2CE81990");
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 {
TellstickDecodedEntry nexa = decode("0x2CE81980");
assertEquals("House Code", 11772006, ((NexaSelfLearning)nexa.getDevice()).getHouse());
assertEquals("Unit Code", 0, ((NexaSelfLearning)nexa.getDevice()).getUnit());
assertFalse("Enabled", ((SwitchEventData)nexa.getData()).isOn());
}
private TellstickDecodedEntry decode(String data){
NexaSelfLearningProtocol nexaProt = new NexaSelfLearningProtocol();
List<TellstickDecodedEntry> list = nexaProt.decode(Converter.hexToByte(data));
return list.get(0);
}
}