[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);
|
addSubscription(DEVICEEVENT);
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/config-status.error.missing-udn");
|
"@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");
|
logger.debug("Polling job");
|
||||||
|
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// 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()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
logger.debug("UPnP device {} not yet registered", getUDN());
|
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() + "\"]");
|
"@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,11 +76,10 @@ public class WemoCrockpotHandler extends WemoBaseThingHandler {
|
|||||||
addSubscription(BASICEVENT);
|
addSubscription(BASICEVENT);
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/config-status.error.missing-udn");
|
"@text/config-status.error.missing-udn");
|
||||||
logger.debug("Cannot initalize WemoCrockpotHandler. UDN not set.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,10 +102,9 @@ public class WemoCrockpotHandler extends WemoBaseThingHandler {
|
|||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// 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()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
logger.debug("UPnP device {} not yet registered", getUDN());
|
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() + "\"]");
|
"@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,11 +89,10 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
|
|||||||
addSubscription(BASICEVENT);
|
addSubscription(BASICEVENT);
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/config-status.error.missing-udn");
|
"@text/config-status.error.missing-udn");
|
||||||
logger.debug("Cannot initalize WemoDimmerHandler. UDN not set.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,10 +116,9 @@ public class WemoDimmerHandler extends WemoBaseThingHandler {
|
|||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// 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()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
logger.debug("UPnP device {} not yet registered", getUDN());
|
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() + "\"]");
|
"@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,11 +72,10 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
|
|||||||
}
|
}
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/config-status.error.missing-udn");
|
"@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 {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// 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()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
logger.debug("UPnP device {} not yet registered", getUDN());
|
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() + "\"]");
|
"@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -178,8 +176,10 @@ public abstract class WemoHandler extends WemoBaseThingHandler {
|
|||||||
logger.trace("New state '{}' for device '{}' received", value, getThing().getUID());
|
logger.trace("New state '{}' for device '{}' received", value, getThing().getUID());
|
||||||
this.onValueReceived(variable, value, actionService + "1");
|
this.onValueReceived(variable, value, actionService + "1");
|
||||||
}
|
}
|
||||||
|
updateStatus(ThingStatus.ONLINE);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("Failed to get actual state for device '{}': {}", getThing().getUID(), e.getMessage());
|
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);
|
addSubscription(BASICEVENT);
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/config-status.error.missing-udn");
|
"@text/config-status.error.missing-udn");
|
||||||
logger.debug("Cannot initalize WemoHolmesHandler. UDN not set.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,10 +117,9 @@ public class WemoHolmesHandler extends WemoBaseThingHandler {
|
|||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// 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()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
logger.debug("UPnP device {} not yet registered", getUDN());
|
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() + "\"]");
|
"@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,7 +87,7 @@ public class WemoLightHandler extends WemoBaseThingHandler {
|
|||||||
addSubscription(BRIDGEEVENT);
|
addSubscription(BRIDGEEVENT);
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, DEFAULT_REFRESH_INITIAL_DELAY,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, DEFAULT_REFRESH_INITIAL_DELAY,
|
||||||
DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS);
|
DEFAULT_REFRESH_INTERVAL_SECONDS, TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.BRIDGE_OFFLINE);
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.BRIDGE_OFFLINE);
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ public class WemoLightHandler extends WemoBaseThingHandler {
|
|||||||
if (bridgeStatusInfo.getStatus().equals(ThingStatus.ONLINE)) {
|
if (bridgeStatusInfo.getStatus().equals(ThingStatus.ONLINE)) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.BRIDGE_OFFLINE);
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
|
||||||
ScheduledFuture<?> job = this.pollingJob;
|
ScheduledFuture<?> job = this.pollingJob;
|
||||||
if (job != null && !job.isCancelled()) {
|
if (job != null && !job.isCancelled()) {
|
||||||
job.cancel(true);
|
job.cancel(true);
|
||||||
@ -143,10 +143,9 @@ public class WemoLightHandler extends WemoBaseThingHandler {
|
|||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// 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()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
logger.debug("UPnP device {} not yet registered", getUDN());
|
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() + "\"]");
|
"@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,11 +77,10 @@ public class WemoMakerHandler extends WemoBaseThingHandler {
|
|||||||
logger.debug("Initializing WemoMakerHandler for UDN '{}'", configuration.get(UDN));
|
logger.debug("Initializing WemoMakerHandler for UDN '{}'", configuration.get(UDN));
|
||||||
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
pollingJob = scheduler.scheduleWithFixedDelay(this::poll, 0, DEFAULT_REFRESH_INTERVAL_SECONDS,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
} else {
|
} else {
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/config-status.error.missing-udn");
|
"@text/config-status.error.missing-udn");
|
||||||
logger.debug("Cannot initalize WemoMakerHandler. UDN not set.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,10 +104,9 @@ public class WemoMakerHandler extends WemoBaseThingHandler {
|
|||||||
try {
|
try {
|
||||||
logger.debug("Polling job");
|
logger.debug("Polling job");
|
||||||
// Check if the Wemo device is set in the UPnP service registry
|
// 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()) {
|
if (!isUpnpDeviceRegistered()) {
|
||||||
logger.debug("UPnP device {} not yet registered", getUDN());
|
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() + "\"]");
|
"@text/config-status.pending.device-not-registered [\"" + getUDN() + "\"]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class WemoHandlerOSGiTest extends GenericWemoOSGiTest {
|
|||||||
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
|
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
|
||||||
|
|
||||||
waitForAssert(() -> {
|
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
|
// 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);
|
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
|
||||||
|
|
||||||
waitForAssert(() -> {
|
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
|
// 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(() -> {
|
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
|
// 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);
|
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
|
||||||
|
|
||||||
waitForAssert(() -> {
|
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
|
// 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);
|
Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE);
|
||||||
|
|
||||||
waitForAssert(() -> {
|
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
|
// The Device is registered as UPnP Device after the initialization, this will ensure that the polling job will
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user