use of org.openhab.core.thing.ThingStatusDetail in project openhab-addons by openhab.
the class SysteminfoOSGiTest method assertItemState.
private void assertItemState(String acceptedItemType, String itemName, String priority, State expectedState) {
waitForAssert(() -> {
ThingStatusDetail thingStatusDetail = systemInfoThing.getStatusInfo().getStatusDetail();
String description = systemInfoThing.getStatusInfo().getDescription();
assertThat("Thing status detail is " + thingStatusDetail + " with description " + description, systemInfoThing.getStatus(), is(equalTo(ThingStatus.ONLINE)));
});
// The binding starts all refresh tasks in SysteminfoHandler.scheduleUpdates() after this delay !
try {
sleep(SysteminfoHandler.WAIT_TIME_CHANNEL_ITEM_LINK_INIT * 1000);
} catch (InterruptedException e) {
throw new AssertionError("Interrupted while sleeping");
}
GenericItem item;
try {
item = (GenericItem) itemRegistry.getItem(itemName);
} catch (ItemNotFoundException e) {
throw new AssertionError("Item not found in registry");
}
int waitTime;
if (priority.equals("High")) {
waitTime = DEFAULT_TEST_INTERVAL_HIGH * 1000;
} else if (priority.equals("Medium")) {
waitTime = DEFAULT_TEST_INTERVAL_MEDIUM * 1000;
} else {
waitTime = 100;
}
waitForAssert(() -> {
State itemState = item.getState();
assertThat(itemState, is(equalTo(expectedState)));
}, waitTime, DFL_SLEEP_TIME);
}
use of org.openhab.core.thing.ThingStatusDetail in project openhab-core by openhab.
the class ThingManagerImpl method doUnregisterHandler.
private void doUnregisterHandler(final Thing thing, final ThingHandlerFactory thingHandlerFactory) {
logger.debug("Calling unregisterHandler handler for thing '{}' at '{}'.", thing.getUID(), thingHandlerFactory);
safeCaller.create(() -> {
ThingHandler thingHandler = thing.getHandler();
thingHandlerFactory.unregisterHandler(thing);
if (thingHandler != null) {
thingHandler.setCallback(null);
}
thing.setHandler(null);
boolean enabled = !isDisabledByStorage(thing.getUID());
ThingStatusDetail detail = enabled ? ThingStatusDetail.HANDLER_MISSING_ERROR : ThingStatusDetail.DISABLED;
setThingStatus(thing, buildStatusInfo(ThingStatus.UNINITIALIZED, detail));
thingHandlers.remove(thing.getUID());
synchronized (thingHandlersByFactory) {
final Set<ThingHandler> thingHandlers = thingHandlersByFactory.get(thingHandlerFactory);
if (thingHandlers != null) {
thingHandlers.remove(thingHandler);
if (thingHandlers.isEmpty()) {
thingHandlersByFactory.remove(thingHandlerFactory);
}
}
}
}, Runnable.class).build().run();
}
Aggregations