use of org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand in project openhab1-addons by openhab.
the class LightwaverfConvertorTest method testConvertToLightwaveRfMessageOffCommand.
@Test
public void testConvertToLightwaveRfMessageOffCommand() throws Exception {
LightwaverfConvertor convertor = new LightwaverfConvertor();
LightwaveRFCommand command = convertor.convertToLightwaveRfMessage("2", "3", LightwaveRfType.SWITCH, OnOffType.OFF);
LightwaveRFCommand expected = new LightwaveRfOnOffCommand("200,!R2D3F0");
assertEquals(expected.getLightwaveRfCommandString(), command.getLightwaveRfCommandString());
}
use of org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand in project openhab1-addons by openhab.
the class LightwaveRFSenderThread method run.
/**
* Run thread, pulling off any items from the UDP commands buffer, then send
* across network
*/
@Override
public void run() {
try {
LightwaveRFCommand commandToSend = queue.take();
if (!commandToSend.equals(STOP_MESSAGE)) {
CountDownLatch latch = new CountDownLatch(1);
latchMap.putIfAbsent(commandToSend.getMessageId(), latch);
retryCountMap.putIfAbsent(commandToSend.getMessageId(), ONE);
netsendUDP(commandToSend);
boolean unlatched = latch.await(timeoutForOkMessagesMs, TimeUnit.MILLISECONDS);
// logger.info("Unlatched?" + unlatched);
latchMap.remove(commandToSend.getMessageId());
if (!unlatched) {
Integer sendCount = retryCountMap.get(commandToSend.getMessageId());
if (sendCount.intValue() >= MAX_RETRY_ATTEMPS) {
logger.error("Unable to send message {} after {} attempts giving up", commandToSend.getLightwaveRfCommandString(), MAX_RETRY_ATTEMPS);
return;
}
if (!running) {
logger.error("Not retrying message {} as we are stopping", commandToSend.getLightwaveRfCommandString());
return;
}
Integer newRetryCount = Integer.valueOf(sendCount.intValue() + 1);
logger.info("Ok message not received for {}, retrying again. Retry count {}", commandToSend.getLightwaveRfCommandString(), newRetryCount);
retryCountMap.put(commandToSend.getMessageId(), newRetryCount);
queue.addFirst(commandToSend);
} else {
logger.info("Ok message received for {}", commandToSend.getLightwaveRfCommandString());
}
} else {
logger.info("Stop message received");
}
} catch (InterruptedException e) {
logger.error("Error waiting on queue", e);
}
}
use of org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand in project openhab1-addons by openhab.
the class LightwaveRfBinding method internalReceive.
private void internalReceive(String itemName, Type command) {
LightwaveRfItemDirection direction = getDirection(itemName);
if (direction == LightwaveRfItemDirection.IN_AND_OUT || direction == LightwaveRfItemDirection.OUT_ONLY) {
String roomId = getRoomId(itemName);
String deviceId = getDeviceId(itemName);
LightwaveRfType deviceType = getType(itemName);
LightwaveRFCommand lightwaverfMessageString = messageConvertor.convertToLightwaveRfMessage(roomId, deviceId, deviceType, command);
wifiLink.sendLightwaveCommand(lightwaverfMessageString);
} else {
logger.debug("Not sending command[" + command + "] to item[" + itemName + "] as it is IN_ONLY");
}
}
use of org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand in project openhab1-addons by openhab.
the class LightwaveRfWifiLinkTest method testSetHeating.
@Test
@Ignore(value = "This is a functional test to ensure the code is working")
public void testSetHeating() throws Exception {
LightwaveRfWifiLink wifiLink = new LightwaveRfWifiLink(LIGHTWAVE_IP, TRANSMIT_PORT, RECEIVE_PORT, CONVERTOR, TIME_BETWEEN_COMMANDS, TIMEOUT_OK);
wifiLink.start();
LightwaveRFCommand command = new LightwaveRfSetHeatingTemperatureCommand(100, "4", 17);
wifiLink.sendLightwaveCommand(command);
Thread.sleep(THREAD_SLEEP);
}
use of org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand in project openhab1-addons by openhab.
the class LightwaverfConvertorTest method testGetRegistrationCommand.
@Test
public void testGetRegistrationCommand() {
LightwaverfConvertor convertor = new LightwaverfConvertor();
LightwaveRFCommand command = convertor.getRegistrationCommand();
assertEquals(new LightwaveRfDeviceRegistrationCommand(), command);
}
Aggregations