Search in sources :

Example 6 with LightwaveRFCommand

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());
}
Also used : LightwaveRfOnOffCommand(org.openhab.binding.lightwaverf.internal.command.LightwaveRfOnOffCommand) LightwaveRFCommand(org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand) Test(org.junit.Test)

Example 7 with LightwaveRFCommand

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);
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) LightwaveRFCommand(org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand)

Example 8 with LightwaveRFCommand

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");
    }
}
Also used : LightwaveRFCommand(org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand)

Example 9 with LightwaveRFCommand

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);
}
Also used : LightwaveRfSetHeatingTemperatureCommand(org.openhab.binding.lightwaverf.internal.command.LightwaveRfSetHeatingTemperatureCommand) LightwaveRFCommand(org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with LightwaveRFCommand

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);
}
Also used : LightwaveRfDeviceRegistrationCommand(org.openhab.binding.lightwaverf.internal.command.LightwaveRfDeviceRegistrationCommand) LightwaveRFCommand(org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand) Test(org.junit.Test)

Aggregations

LightwaveRFCommand (org.openhab.binding.lightwaverf.internal.command.LightwaveRFCommand)13 Test (org.junit.Test)11 LightwaveRfOnOffCommand (org.openhab.binding.lightwaverf.internal.command.LightwaveRfOnOffCommand)4 Ignore (org.junit.Ignore)3 LightwaveRfDimCommand (org.openhab.binding.lightwaverf.internal.command.LightwaveRfDimCommand)2 LightwaveRfSetHeatingTemperatureCommand (org.openhab.binding.lightwaverf.internal.command.LightwaveRfSetHeatingTemperatureCommand)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 LightwaveRfDeviceRegistrationCommand (org.openhab.binding.lightwaverf.internal.command.LightwaveRfDeviceRegistrationCommand)1 DecimalType (org.openhab.core.library.types.DecimalType)1 PercentType (org.openhab.core.library.types.PercentType)1