From c77d3b93f23a3bc572f4031204be8013c080ca8b Mon Sep 17 00:00:00 2001 From: morph166955 <53797132+morph166955@users.noreply.github.com> Date: Mon, 25 Jan 2021 16:19:13 -0600 Subject: [PATCH] [samsungtv] WebSocket TVs stay UNKNOWN until first power-on #9764 (#9923) Fixed #9764 Signed-off-by: morph166955 --- .../internal/handler/SamsungTvHandler.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.samsungtv/src/main/java/org/openhab/binding/samsungtv/internal/handler/SamsungTvHandler.java b/bundles/org.openhab.binding.samsungtv/src/main/java/org/openhab/binding/samsungtv/internal/handler/SamsungTvHandler.java index 8c09e86d019..267e210001a 100644 --- a/bundles/org.openhab.binding.samsungtv/src/main/java/org/openhab/binding/samsungtv/internal/handler/SamsungTvHandler.java +++ b/bundles/org.openhab.binding.samsungtv/src/main/java/org/openhab/binding/samsungtv/internal/handler/SamsungTvHandler.java @@ -239,14 +239,26 @@ public class SamsungTvHandler extends BaseThingHandler implements RegistryListen private void checkAndCreateServices() { logger.debug("Check and create missing UPnP services"); + boolean isOnline = false; + for (Device device : upnpService.getRegistry().getDevices()) { - createService((RemoteDevice) device); + if (createService((RemoteDevice) device) == true) { + isOnline = true; + } + } + + if (isOnline == true) { + logger.debug("Device was online"); + putOnline(); + } else { + logger.debug("Device was NOT online"); + putOffline(); } checkCreateManualConnection(); } - private synchronized void createService(RemoteDevice device) { + private synchronized boolean createService(RemoteDevice device) { if (configuration.hostName != null && configuration.hostName.equals(device.getIdentity().getDescriptorURL().getHost())) { String modelName = device.getDetails().getModelDetails().getModelName(); @@ -275,8 +287,9 @@ public class SamsungTvHandler extends BaseThingHandler implements RegistryListen logger.debug("Service rediscovered, clearing caches: {}, {} ({})", modelName, type, udn); existingService.clearCache(); } - putOnline(); + return true; } + return false; } private @Nullable SamsungTvService findServiceInstance(String serviceName) {