From 5a3559caa283a92ec1d8feb56998a0d847cb901e Mon Sep 17 00:00:00 2001 From: carlospg79 Date: Tue, 14 Dec 2021 00:36:53 +0100 Subject: [PATCH] Fixes #8646 - Bugfix for openHAB > 3.1.x Signed-off-by: Carlos Primo Signed-off-by: carlospg79 --- .../lgtvserial/internal/handler/LgTvSerialHandler.java | 6 ++++++ .../internal/protocol/serial/LGSerialCommunicator.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.lgtvserial/src/main/java/org/openhab/binding/lgtvserial/internal/handler/LgTvSerialHandler.java b/bundles/org.openhab.binding.lgtvserial/src/main/java/org/openhab/binding/lgtvserial/internal/handler/LgTvSerialHandler.java index 276657a147013..94c4d3221e4ec 100644 --- a/bundles/org.openhab.binding.lgtvserial/src/main/java/org/openhab/binding/lgtvserial/internal/handler/LgTvSerialHandler.java +++ b/bundles/org.openhab.binding.lgtvserial/src/main/java/org/openhab/binding/lgtvserial/internal/handler/LgTvSerialHandler.java @@ -170,6 +170,12 @@ public void onFailure(ChannelUID channel, LGSerialResponse response) { if (updateJob == null || updateJob.isCancelled()) { updateJob = scheduler.scheduleWithFixedDelay(eventRunnable, 0, EVENT_REFRESH_INTERVAL, TimeUnit.SECONDS); } + // trigger REFRESH commands for all linked Channels to start polling + getThing().getChannels().forEach(channel -> { + if (isLinked(channel.getUID())) { + channelLinked(channel.getUID()); + } + }); updateStatus(ThingStatus.ONLINE); } diff --git a/bundles/org.openhab.binding.lgtvserial/src/main/java/org/openhab/binding/lgtvserial/internal/protocol/serial/LGSerialCommunicator.java b/bundles/org.openhab.binding.lgtvserial/src/main/java/org/openhab/binding/lgtvserial/internal/protocol/serial/LGSerialCommunicator.java index b16ed23d94f1d..45b69ba5d275b 100644 --- a/bundles/org.openhab.binding.lgtvserial/src/main/java/org/openhab/binding/lgtvserial/internal/protocol/serial/LGSerialCommunicator.java +++ b/bundles/org.openhab.binding.lgtvserial/src/main/java/org/openhab/binding/lgtvserial/internal/protocol/serial/LGSerialCommunicator.java @@ -79,7 +79,7 @@ public synchronized void write(LGSerialCommand command, String rawCommand, Chann int data; int len = 0; int offset = 0; - while ((data = input.read()) > -1) { + while (input.available() > 0 && (data = input.read()) > -1) { if (data == 'x') { String result = new String(buffer, offset, len); if (logger.isDebugEnabled()) {