From 4548f69000387436f3fe382dc02575a7caf1d966 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Wed, 17 Jan 2024 01:53:52 -0600 Subject: [PATCH] [vizio] Prevent thing status from bouncing offline (#16291) * Prevent thing status from bouncing offline Signed-off-by: Michael Lobstein --- .../vizio/internal/handler/VizioHandler.java | 49 +++++++------------ .../resources/OH-INF/i18n/vizio.properties | 12 +---- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/bundles/org.openhab.binding.vizio/src/main/java/org/openhab/binding/vizio/internal/handler/VizioHandler.java b/bundles/org.openhab.binding.vizio/src/main/java/org/openhab/binding/vizio/internal/handler/VizioHandler.java index 80539e26d5c..0a8a6c637ae 100644 --- a/bundles/org.openhab.binding.vizio/src/main/java/org/openhab/binding/vizio/internal/handler/VizioHandler.java +++ b/bundles/org.openhab.binding.vizio/src/main/java/org/openhab/binding/vizio/internal/handler/VizioHandler.java @@ -86,6 +86,7 @@ public class VizioHandler extends BaseThingHandler { private List userConfigApps = new ArrayList<>(); private Object sequenceLock = new Object(); + private int failCount = 0; private int pairingDeviceId = -1; private int pairingToken = -1; private Long currentInputHash = 0L; @@ -217,10 +218,16 @@ public class VizioHandler extends BaseThingHandler { } } updateStatus(ThingStatus.ONLINE); + failCount = 0; } catch (VizioException e) { logger.debug("Unable to retrieve Vizio TV power mode info. Exception: {}", e.getMessage(), e); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-get-power"); + // A communication error must occur 3 times before updating the thing status + failCount++; + if (failCount > 2) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "@text/offline.communication-error-polling"); + } + return; } if (powerOn && (isLinked(VOLUME) || isLinked(MUTE))) { @@ -263,8 +270,6 @@ public class VizioHandler extends BaseThingHandler { } catch (VizioException e) { logger.debug("Unable to retrieve Vizio TV current audio settings. Exception: {}", e.getMessage(), e); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-get-audio"); } } @@ -280,8 +285,6 @@ public class VizioHandler extends BaseThingHandler { } } catch (VizioException e) { logger.debug("Unable to retrieve Vizio TV current input. Exception: {}", e.getMessage(), e); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-get-input"); } } @@ -318,8 +321,6 @@ public class VizioHandler extends BaseThingHandler { } } catch (VizioException e) { logger.debug("Unable to retrieve Vizio TV current running app. Exception: {}", e.getMessage(), e); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-get-app"); } } } @@ -401,10 +402,8 @@ public class VizioHandler extends BaseThingHandler { powerOn = false; } } catch (VizioException e) { - logger.debug("Unable to send power {} command to the Vizio TV, Exception: {}", command, + logger.warn("Unable to send power {} command to the Vizio TV, Exception: {}", command, e.getMessage()); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-set-power"); } } break; @@ -430,12 +429,10 @@ public class VizioHandler extends BaseThingHandler { .changeVolume(String.format(MODIFY_INT_SETTING_JSON, volume, currentVolumeHash)); currentVolumeHash = 0L; } catch (VizioException e) { - logger.debug("Unable to set volume on the Vizio TV, command volume: {}, Exception: {}", + logger.warn("Unable to set volume on the Vizio TV, command volume: {}, Exception: {}", command, e.getMessage()); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-set-volume"); } catch (NumberFormatException e) { - logger.debug("Unable to parse command volume value {} as int", command); + logger.warn("Unable to parse command volume value {} as int", command); } } break; @@ -451,10 +448,8 @@ public class VizioHandler extends BaseThingHandler { currentMute = false; } } catch (VizioException e) { - logger.debug("Unable to send mute {} command to the Vizio TV, Exception: {}", command, + logger.warn("Unable to send mute {} command to the Vizio TV, Exception: {}", command, e.getMessage()); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-set-mute"); } } break; @@ -474,10 +469,8 @@ public class VizioHandler extends BaseThingHandler { .changeInput(String.format(MODIFY_STRING_SETTING_JSON, command, currentInputHash)); currentInputHash = 0L; } catch (VizioException e) { - logger.debug("Unable to set current source on the Vizio TV, source: {}, Exception: {}", + logger.warn("Unable to set current source on the Vizio TV, source: {}, Exception: {}", command, e.getMessage()); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-set-source"); } } break; @@ -491,14 +484,12 @@ public class VizioHandler extends BaseThingHandler { if (selectedApp.isPresent()) { communicator.launchApp(selectedApp.get().getConfig()); } else { - logger.debug("Unknown app name: '{}', check that it exists in App List configuration", + logger.warn("Unknown app name: '{}', check that it exists in App List configuration", command); } } catch (VizioException e) { - logger.debug("Unable to launch app name: '{}' on the Vizio TV, Exception: {}", command, + logger.warn("Unable to launch app name: '{}' on the Vizio TV, Exception: {}", command, e.getMessage()); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-launch-app"); } } break; @@ -508,10 +499,8 @@ public class VizioHandler extends BaseThingHandler { try { handleControlCommand(command); } catch (VizioException e) { - logger.debug("Unable to send control command: '{}' to the Vizio TV, Exception: {}", command, + logger.warn("Unable to send control command: '{}' to the Vizio TV, Exception: {}", command, e.getMessage()); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-send-cmd"); } } break; @@ -521,10 +510,8 @@ public class VizioHandler extends BaseThingHandler { KeyCommand keyCommand = KeyCommand.valueOf(command.toString().toUpperCase(Locale.ENGLISH)); communicator.sendKeyPress(keyCommand.getJson()); } catch (IllegalArgumentException | VizioException e) { - logger.debug("Unable to send keypress to the Vizio TV, key: {}, Exception: {}", command, + logger.warn("Unable to send keypress to the Vizio TV, key: {}, Exception: {}", command, e.getMessage()); - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "@text/offline.communication-error-send-key"); } } break; diff --git a/bundles/org.openhab.binding.vizio/src/main/resources/OH-INF/i18n/vizio.properties b/bundles/org.openhab.binding.vizio/src/main/resources/OH-INF/i18n/vizio.properties index 14273f1b3c3..2378ddd33fd 100644 --- a/bundles/org.openhab.binding.vizio/src/main/resources/OH-INF/i18n/vizio.properties +++ b/bundles/org.openhab.binding.vizio/src/main/resources/OH-INF/i18n/vizio.properties @@ -68,14 +68,4 @@ channel-type.vizio.source.description = Select the Source Input for the TV offline.configuration-error-hostname = Host Name must be specified offline.configuration-error-authtoken = Auth Token must be specified, see documentation for details offline.configuration-error-applist = Invalid App List Configuration in thing configuration -offline.communication-error-get-power = Unable to retrieve power mode info from TV -offline.communication-error-get-audio = Unable to retrieve current audio settings from TV -offline.communication-error-get-input = Unable to retrieve current input from TV -offline.communication-error-get-app = Unable to retrieve current running app from TV -offline.communication-error-set-power = Unable to send power command to the TV -offline.communication-error-set-volume = Unable to set volume on the TV -offline.communication-error-set-mute = Unable to send mute command to the TV -offline.communication-error-set-source = Unable to set current source on the TV -offline.communication-error-launch-app = Unable to launch app on the TV -offline.communication-error-send-cmd = Unable to send control command to the TV -offline.communication-error-send-key = Unable to send keypress to the TV +offline.communication-error-polling = Unable to communicate with the TV