mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[wemo] Fix thing status transitions (#12416)
* 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>
This commit is contained in:
parent
3ed28ae745
commit
a3b6f74764
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user