Tellstic event bugfix. issue 15
Former-commit-id: eed3e3bacbb7adfb27f31f4f1c3a47f1b6e884fd
This commit is contained in:
parent
ff9709b6d2
commit
eceafa762c
5 changed files with 27 additions and 14 deletions
|
|
@ -226,8 +226,10 @@ public class ControllerManager implements HalSensorReportListener,
|
|||
|
||||
public void send(Event event){
|
||||
HalEventController controller = getControllerInstance(event.getController());
|
||||
if(controller != null)
|
||||
if(controller != null) {
|
||||
controller.send(event.getDeviceData());
|
||||
reportReceived(event.getDeviceData()); // save action to db
|
||||
}
|
||||
else
|
||||
logger.warning("No controller found for event id: "+ event.getId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package se.hal.page;
|
|||
|
||||
import se.hal.ControllerManager;
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.intf.HalHttpPage;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.SwitchEventData;
|
||||
|
|
@ -39,11 +40,12 @@ public class EventOverviewHttpPage extends HalHttpPage {
|
|||
if(request.containsKey("action")){
|
||||
// change event data
|
||||
Event event = Event.getEvent(db, id);
|
||||
if (event instanceof SwitchEventData){
|
||||
if ( ! ((SwitchEventData)event).isOn())
|
||||
((SwitchEventData)event).turnOn();
|
||||
HalEventData eventData = event.getDeviceData();
|
||||
if (eventData instanceof SwitchEventData){
|
||||
if ( request.containsKey("data") && "on".equals(request.get("data")))
|
||||
((SwitchEventData)eventData).turnOn();
|
||||
else
|
||||
((SwitchEventData)event).turnOff();
|
||||
((SwitchEventData)eventData).turnOff();
|
||||
}
|
||||
ControllerManager.getInstance().send(event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,9 +83,12 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
|
|||
serial.setComPortTimeouts(
|
||||
SerialPort.TIMEOUT_READ_BLOCKING, 0, 0);
|
||||
|
||||
//in = new InputStreamLogger(serial.getInputStream());
|
||||
//out = new OutputStreamLogger(serial.getOutputStream());
|
||||
in = new InputStreamLogger(serial.getInputStream());
|
||||
out = new OutputStreamLogger(serial.getOutputStream());
|
||||
|
||||
|
||||
Executors.newSingleThreadExecutor().execute(this);
|
||||
}
|
||||
|
||||
|
|
@ -166,15 +169,15 @@ public class TellstickSerialComm implements Runnable, HalSensorController, HalEv
|
|||
write(prot.encode());
|
||||
try {
|
||||
this.wait();
|
||||
prot.setTimestamp(System.currentTimeMillis());
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.SEVERE, null, e);
|
||||
}
|
||||
}
|
||||
public void write(String data) {
|
||||
try {
|
||||
//for(int i=0; i<data.length();i++)
|
||||
// out.write(0xFF & data.charAt(i));
|
||||
out.write(data.getBytes(Charset.forName("UTF-8")));
|
||||
for(int i=0; i<data.length();i++)
|
||||
out.write(0xFF & data.charAt(i));
|
||||
out.write('\n');
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ public class TelstickSerialCommNexaOnOffTest {
|
|||
|
||||
NexaSelfLearning nexa = new NexaSelfLearning();
|
||||
//nexa.setHouse(11772006);
|
||||
nexa.setHouse(15087918);
|
||||
nexa.setHouse(14160770);
|
||||
nexa.setGroup(0);
|
||||
nexa.setUnit(0);
|
||||
nexa.setUnit(1);
|
||||
|
||||
System.out.println("Up and Running");
|
||||
while(true) {
|
||||
|
|
|
|||
|
|
@ -48,20 +48,26 @@ public class NexaSelfLearningTest {
|
|||
|
||||
@org.junit.Test
|
||||
public void decode_ON() throws Exception {
|
||||
NexaSelfLearning nexa = new NexaSelfLearning();
|
||||
nexa.decode(Converter.hexToByte("0x2CE81990"));
|
||||
NexaSelfLearning nexa = decode("0x2CE81990");
|
||||
|
||||
assertEquals("House Code", 11772006, nexa.getHouse());
|
||||
assertEquals("Unit Code", 1, nexa.getUnit());
|
||||
assertTrue("Enabled", nexa.isOn());
|
||||
|
||||
|
||||
}
|
||||
@org.junit.Test
|
||||
public void decode_OFF() throws Exception {
|
||||
NexaSelfLearning nexa = new NexaSelfLearning();
|
||||
nexa.decode(Converter.hexToByte("0x2CE81980"));
|
||||
NexaSelfLearning nexa = decode("0x2CE81980");
|
||||
|
||||
assertEquals("House Code", 11772006, nexa.getHouse());
|
||||
assertEquals("Unit Code", 1, nexa.getUnit());
|
||||
assertFalse("Enabled", nexa.isOn());
|
||||
}
|
||||
|
||||
private NexaSelfLearning decode(String data){
|
||||
NexaSelfLearning nexa = new NexaSelfLearning();
|
||||
nexa.decode(Converter.hexToByte(data));
|
||||
return nexa;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue