]> git.basschouten.com Git - openhab-addons.git/commitdiff
[wemo] Fix thing status transitions (#12416)
authorJacob Laursen <jacob-github@vindvejr.dk>
Sat, 5 Mar 2022 00:08:45 +0000 (01:08 +0100)
committerGitHub <noreply@github.com>
Sat, 5 Mar 2022 00:08:45 +0000 (01:08 +0100)
* Fix status transitions

Fixes #12415

* Fix integration tests
* Fix missing status update for some devices after HTTP call

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCoffeeHandler.java
bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoCrockpotHandler.java
bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoDimmerHandler.java
bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHandler.java
bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoHolmesHandler.java
bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoLightHandler.java
bundles/org.openhab.binding.wemo/src/main/java/org/openhab/binding/wemo/internal/handler/WemoMakerHandler.java
itests/org.openhab.binding.wemo.tests/src/main/java/org/openhab/binding/wemo/internal/handler/test/WemoHandlerOSGiTest.java
itests/org.openhab.binding.wemo.tests/src/main/java/org/openhab/binding/wemo/internal/handler/test/WemoLightHandlerOSGiTest.java
itests/org.openhab.binding.wemo.tests/src/main/java/org/openhab/binding/wemo/internal/handler/test/WemoMakerHandlerOSGiTest.java

index 22f93ae9f531f8ee188a2cdda40ea44bd2231bf3..7714ac2c7b0ab4e2d64ffc1304b4e2275b22e496 100644 (file)
@@ -85,11 +85,10 @@ public class WemoCoffeeHandler extends WemoBaseThingHandler {
             addSubscription(DEVICEEVENT);
             pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
                     TimeUnit.SECONDS);
-            updateStatus(ThingStatus.ONLINE);
+            updateStatus(ThingStatus.UNKNOWN);
         } else {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                     "@text/config-status.error.missing-udn");
-            logger.debug("Cannot initalize WemoCoffeeHandler. UDN not set.");
         }
     }
 
@@ -113,10 +112,9 @@ public class WemoCoffeeHandler extends WemoBaseThingHandler {
                 logger.debug("Polling job");
 
                 // Check if the Wemo device is set in the UPnP service registry
-                // If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
                 if (!isUpnpDeviceRegistered()) {
                     logger.debug("UPnP device {} not yet registered", getUDN());
-                    updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_PENDING,
+                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
                             "@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
                     return;
                 }
index 0690d94e31ed31ed191861a072cdcbf0d06b067d..435d544180d00cae01f4c30ac8ea5362662cc744 100644 (file)
@@ -76,11 +76,10 @@ public class WemoCrockpotHandler extends WemoBaseThingHandler {
             addSubscription(BASICEVENT);
             pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
                     TimeUnit.SECONDS);
-            updateStatus(ThingStatus.ONLINE);
+            updateStatus(ThingStatus.UNKNOWN);
         } else {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                     "@text/config-status.error.missing-udn");
-            logger.debug("Cannot initalize WemoCrockpotHandler. UDN not set.");
         }
     }
 
@@ -103,10 +102,9 @@ public class WemoCrockpotHandler extends WemoBaseThingHandler {
             try {
                 logger.debug("Polling job");
                 // Check if the Wemo device is set in the UPnP service registry
-                // If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
                 if (!isUpnpDeviceRegistered()) {
                     logger.debug("UPnP device {} not yet registered", getUDN());
-                    updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_PENDING,
+                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
                             "@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
                     return;
                 }
index e7488d75ca224fc2201eaff1b0d1868ee70577ef..4d43e87d97b39c9a7adc3d0fbcf065f71d2357f9 100644 (file)
@@ -89,11 +89,10 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
             addSubscription(BASICEVENT);
             pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
                     TimeUnit.SECONDS);
-            updateStatus(ThingStatus.ONLINE);
+            updateStatus(ThingStatus.UNKNOWN);
         } else {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                     "@text/config-status.error.missing-udn");
-            logger.debug("Cannot initalize WemoDimmerHandler. UDN not set.");
         }
     }
 
@@ -117,10 +116,9 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
             try {
                 logger.debug("Polling job");
                 // Check if the Wemo device is set in the UPnP service registry
-                // If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
                 if (!isUpnpDeviceRegistered()) {
                     logger.debug("UPnP device {} not yet registered", getUDN());
-                    updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_PENDING,
+                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
                             "@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
                     return;
                 }
index 0953fe6287a3c5d60827fcd0fd3d3ccda01bf599..4e16cce218771f416badc77d72c28c4478185153 100644 (file)
@@ -72,11 +72,10 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
             }
             pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
                     TimeUnit.SECONDS);
-            updateStatus(ThingStatus.ONLINE);
+            updateStatus(ThingStatus.UNKNOWN);
         } else {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                     "@text/config-status.error.missing-udn");
-            logger.debug("Cannot initalize WemoHandler. UDN not set.");
         }
     }
 
@@ -100,10 +99,9 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
             try {
                 logger.debug("Polling job");
                 // Check if the Wemo device is set in the UPnP service registry
-                // If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
                 if (!isUpnpDeviceRegistered()) {
                     logger.debug("UPnP device {} not yet registered", getUDN());
-                    updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_PENDING,
+                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
                             "@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
                     return;
                 }
@@ -178,8 +176,10 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
                 logger.trace("New state '{}' for device '{}' received", value, getThing().getUID());
                 this.onValueReceived(variable, value, actionService + "1");
             }
+            updateStatus(ThingStatus.ONLINE);
         } catch (Exception e) {
             logger.warn("Failed to get actual state for device '{}': {}", getThing().getUID(), e.getMessage());
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
         }
     }
 }
index b8b5144a3d81fe0f3a952c5fa2612f8541706322..041707008b233bc7dd779bbd3603dfab9dc48779 100644 (file)
@@ -90,11 +90,10 @@ public class WemoHolmesHandler extends WemoBaseThingHandler {
             addSubscription(BASICEVENT);
             pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
                     TimeUnit.SECONDS);
-            updateStatus(ThingStatus.ONLINE);
+            updateStatus(ThingStatus.UNKNOWN);
         } else {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                     "@text/config-status.error.missing-udn");
-            logger.debug("Cannot initalize WemoHolmesHandler. UDN not set.");
         }
     }
 
@@ -118,10 +117,9 @@ public class WemoHolmesHandler extends WemoBaseThingHandler {
             try {
                 logger.debug("Polling job");
                 // Check if the Wemo device is set in the UPnP service registry
-                // If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
                 if (!isUpnpDeviceRegistered()) {
                     logger.debug("UPnP device {} not yet registered", getUDN());
-                    updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_PENDING,
+                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
                             "@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
                     return;
                 }
index 2bc020c1841b8fb16d24307b3a79c29190c74bcf..2956ea3c9316d7f751910cdc4f484eb7a6ce6103 100644 (file)
@@ -87,7 +87,7 @@ public class WemoLightHandler extends WemoBaseThingHandler {
             addSubscription(BRIDGEEVENT);
             pollingJob = scheduler.scheduleWithFixedDelay(this::poll, DEFAULT_REFRESH_INITIAL_DELAY,
                     DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS);
-            updateStatus(ThingStatus.ONLINE);
+            updateStatus(ThingStatus.UNKNOWN);
         } else {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.BRIDGE_OFFLINE);
         }
@@ -98,7 +98,7 @@ public class WemoLightHandler extends WemoBaseThingHandler {
         if (bridgeStatusInfo.getStatus().equals(ThingStatus.ONLINE)) {
             updateStatus(ThingStatus.ONLINE);
         } else {
-            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.BRIDGE_OFFLINE);
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
             ScheduledFuture<?> job = this.pollingJob;
             if (job != null && !job.isCancelled()) {
                 job.cancel(true);
@@ -143,10 +143,9 @@ public class WemoLightHandler extends WemoBaseThingHandler {
             try {
                 logger.debug("Polling job");
                 // Check if the Wemo device is set in the UPnP service registry
-                // If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
                 if (!isUpnpDeviceRegistered()) {
                     logger.debug("UPnP device {} not yet registered", getUDN());
-                    updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_PENDING,
+                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
                             "@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
                     return;
                 }
index dbe7dd410d38edc460259ad8c6f38b038a42b93c..a94d378a4c50e75e661437cca4008c0bbe94d06e 100644 (file)
@@ -77,11 +77,10 @@ public class WemoMakerHandler extends WemoBaseThingHandler {
             logger.debug("Initializing WemoMakerHandler for UDN '{}'", configuration.get(UDN));
             pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
                     TimeUnit.SECONDS);
-            updateStatus(ThingStatus.ONLINE);
+            updateStatus(ThingStatus.UNKNOWN);
         } else {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                     "@text/config-status.error.missing-udn");
-            logger.debug("Cannot initalize WemoMakerHandler. UDN not set.");
         }
     }
 
@@ -105,10 +104,9 @@ public class WemoMakerHandler extends WemoBaseThingHandler {
             try {
                 logger.debug("Polling job");
                 // Check if the Wemo device is set in the UPnP service registry
-                // If not, set the thing state to ONLINE/CONFIG-PENDING and wait for the next poll
                 if (!isUpnpDeviceRegistered()) {
                     logger.debug("UPnP device {} not yet registered", getUDN());
-                    updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_PENDING,
+                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
                             "@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
                     return;
                 }
index c8f3ad0d19d2d3c11cf3ba056dc8a495f255238d..ddd01225919efa6c808cd949410064d690c71bd4 100644 (file)
@@ -75,7 +75,7 @@ public class WemoHandlerOSGiTest extends GenericWemoOSGiTest {
         Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
 
         waitForAssert(() -> {
-            assertThat(thing.getStatus(), is(ThingStatus.ONLINE));
+            assertThat(thing.getStatus(), is(ThingStatus.UNKNOWN));
         });
 
         // The device is registered as UPnP Device after the initialization, this will ensure that the polling job will
@@ -111,7 +111,7 @@ public class WemoHandlerOSGiTest extends GenericWemoOSGiTest {
         Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
 
         waitForAssert(() -> {
-            assertThat(thing.getStatus(), is(ThingStatus.ONLINE));
+            assertThat(thing.getStatus(), is(ThingStatus.OFFLINE));
         });
 
         // The device is registered as UPnP Device after the initialization, this will ensure that the polling job will
index 8442b83cc286e6a51cb99baac2eaa213f670af97..1505fec2ac9d03a32d8cd4d8f75f4a27d13bb547 100644 (file)
@@ -160,7 +160,7 @@ public class WemoLightHandlerOSGiTest extends GenericWemoLightOSGiTestParent {
         });
 
         waitForAssert(() -> {
-            assertThat(thing.getStatus(), is(ThingStatus.ONLINE));
+            assertThat(thing.getStatus(), is(ThingStatus.UNKNOWN));
         });
 
         // The device is registered as UPnP Device after the initialization, this will ensure that the polling job will
index fa882614066bcaf8ad38649e2faa39a2f7d45471..9ec689d295d32f85abfedddbc551a625bf5c80b8 100644 (file)
@@ -76,7 +76,7 @@ public class WemoMakerHandlerOSGiTest extends GenericWemoOSGiTest {
         Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
 
         waitForAssert(() -> {
-            assertThat(thing.getStatus(), is(ThingStatus.ONLINE));
+            assertThat(thing.getStatus(), is(ThingStatus.OFFLINE));
         });
 
         // The Device is registered as UPnP Device after the initialization, this will ensure that the polling job will
@@ -112,7 +112,7 @@ public class WemoMakerHandlerOSGiTest extends GenericWemoOSGiTest {
         Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
 
         waitForAssert(() -> {
-            assertThat(thing.getStatus(), is(ThingStatus.ONLINE));
+            assertThat(thing.getStatus(), is(ThingStatus.OFFLINE));
         });
 
         // The Device is registered as UPnP Device after the initialization, this will ensure that the polling job will