From 1b5df97af5a7a40e5660ec4bd7a69c92e86e82d0 Mon Sep 17 00:00:00 2001 From: miloit Date: Thu, 31 Dec 2020 12:21:49 +0100 Subject: [PATCH] [yioremote] BugFix sendIRCode action (#9574) * Corrected sendIRCode handler Signed-off-by: Michael Loercher * Update YIOremoteDockHandler.java Updating IR receiver switch handler so it's running now Solved issue during triggering channel while it was disposed Signed-off-by: Michael Loercher * Update YIOremoteDockHandler.java Signed-off-by: Michael Loercher --- .../internal/YIOremoteDockHandler.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.yioremote/src/main/java/org/openhab/binding/yioremote/internal/YIOremoteDockHandler.java b/bundles/org.openhab.binding.yioremote/src/main/java/org/openhab/binding/yioremote/internal/YIOremoteDockHandler.java index 41767b877..e89dab324 100644 --- a/bundles/org.openhab.binding.yioremote/src/main/java/org/openhab/binding/yioremote/internal/YIOremoteDockHandler.java +++ b/bundles/org.openhab.binding.yioremote/src/main/java/org/openhab/binding/yioremote/internal/YIOremoteDockHandler.java @@ -44,7 +44,6 @@ import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.thing.binding.ThingHandlerService; import org.openhab.core.types.Command; import org.openhab.core.types.State; -import org.openhab.core.types.UnDefType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -117,8 +116,6 @@ public class YIOremoteDockHandler extends BaseThingHandler { recievedJson = convertStringToJsonObject(receivedMessage); if (recievedJson.size() > 0) { if (decodeReceivedMessage(recievedJson)) { - triggerChannel(getChannelUuid(GROUP_OUTPUT, STATUS_STRING_CHANNEL)); - updateChannelString(GROUP_OUTPUT, STATUS_STRING_CHANNEL, receivedStatus); switch (yioRemoteDockActualStatus) { case CONNECTION_ESTABLISHED: case AUTHENTICATION_PROCESS: @@ -127,6 +124,12 @@ public class YIOremoteDockHandler extends BaseThingHandler { case COMMUNICATION_ERROR: reconnectWebsocket(); break; + case AUTHENTICATION_COMPLETE: + case CHECK_PONG: + case SEND_PING: + updateChannelString(GROUP_OUTPUT, STATUS_STRING_CHANNEL, receivedStatus); + triggerChannel(getChannelUuid(GROUP_OUTPUT, STATUS_STRING_CHANNEL)); + break; default: break; } @@ -202,6 +205,7 @@ public class YIOremoteDockHandler extends BaseThingHandler { } else { irCodeReceivedHandler.setCode(""); } + logger.debug("ir_receive message {}", irCodeReceivedHandler.getCode()); heartBeat = true; success = true; @@ -266,6 +270,8 @@ public class YIOremoteDockHandler extends BaseThingHandler { if (RECEIVER_SWITCH_CHANNEL.equals(channelUID.getIdWithoutGroup())) { switch (yioRemoteDockActualStatus) { case AUTHENTICATION_COMPLETE: + case SEND_PING: + case CHECK_PONG: if (command == OnOffType.ON) { logger.debug("YIODOCKRECEIVERSWITCH ON procedure: Switching IR Receiver on"); sendMessage(YioRemoteMessages.IR_RECEIVER_ON, ""); @@ -283,12 +289,20 @@ public class YIOremoteDockHandler extends BaseThingHandler { } public void sendIRCode(@Nullable String irCode) { - if (irCode != null && yioRemoteDockActualStatus.equals(YioRemoteDockHandleStatus.AUTHENTICATION_COMPLETE)) { - if (irCode.matches("[0-9]?[0-9][;]0[xX][0-9a-fA-F]+[;][0-9]+[;][0-9]")) { - sendMessage(YioRemoteMessages.IR_SEND, irCode); + if (irCode != null) { + if (yioRemoteDockActualStatus.equals(YioRemoteDockHandleStatus.AUTHENTICATION_COMPLETE) + || yioRemoteDockActualStatus.equals(YioRemoteDockHandleStatus.SEND_PING) + || yioRemoteDockActualStatus.equals(YioRemoteDockHandleStatus.CHECK_PONG)) { + if (irCode.matches("[0-9]?[0-9][;]0[xX][0-9a-fA-F]+[;][0-9]+[;][0-9]")) { + sendMessage(YioRemoteMessages.IR_SEND, irCode); + } else { + logger.warn("Wrong ir code format {}", irCode); + } } else { - logger.warn("Wrong ir code format {}", irCode); + logger.debug("Wrong Dock Statusfor sending {}", irCode); } + } else { + logger.warn("No ir code {}", irCode); } } @@ -312,6 +326,8 @@ public class YIOremoteDockHandler extends BaseThingHandler { if (authenticationOk) { yioRemoteDockActualStatus = YioRemoteDockHandleStatus.AUTHENTICATION_COMPLETE; updateStatus(ThingStatus.ONLINE); + updateState(STATUS_STRING_CHANNEL, StringType.EMPTY); + updateState(RECEIVER_SWITCH_CHANNEL, OnOffType.OFF); webSocketPollingJob = scheduler.scheduleWithFixedDelay(this::pollingWebsocketJob, 0, 60, TimeUnit.SECONDS); } else { @@ -323,7 +339,6 @@ public class YIOremoteDockHandler extends BaseThingHandler { yioRemoteDockActualStatus = YioRemoteDockHandleStatus.COMMUNICATION_ERROR; updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Connection lost no ping from YIO DOCK"); - updateState(GROUP_OUTPUT, STATUS_STRING_CHANNEL, UnDefType.UNDEF); break; } } @@ -367,7 +382,6 @@ public class YIOremoteDockHandler extends BaseThingHandler { yioRemoteDockActualStatus = YioRemoteDockHandleStatus.COMMUNICATION_ERROR; updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Connection lost no ping from YIO DOCK"); - updateState(GROUP_OUTPUT, STATUS_STRING_CHANNEL, UnDefType.UNDEF); break; } } @@ -456,7 +470,7 @@ public class YIOremoteDockHandler extends BaseThingHandler { case IR_SEND: irCodeSendHandler.setCode(messagePayload); yioremoteDockwebSocketClient.sendMessage(irCodeSendMessageHandler.getIRcodeSendMessageString()); - logger.debug("sending heartBeat message: {}", irCodeSendMessageHandler.getIRcodeSendMessageString()); + logger.debug("sending IR code: {}", irCodeSendMessageHandler.getIRcodeSendMessageString()); break; } }