Search in sources :

Example 16 with ThingStatusDetail

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);
}
Also used : GenericItem(org.openhab.core.items.GenericItem) State(org.openhab.core.types.State) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 17 with ThingStatusDetail

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();
}
Also used : ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) ThingHandler(org.openhab.core.thing.binding.ThingHandler)

Aggregations

ThingStatusDetail (org.openhab.core.thing.ThingStatusDetail)17 ThingStatus (org.openhab.core.thing.ThingStatus)14 State (org.openhab.core.types.State)9 IOException (java.io.IOException)4 AbstractRioHandlerCallback (org.openhab.binding.russound.internal.rio.AbstractRioHandlerCallback)4 StatefulHandlerCallback (org.openhab.binding.russound.internal.rio.StatefulHandlerCallback)4 ThingHandler (org.openhab.core.thing.binding.ThingHandler)4 HashMap (java.util.HashMap)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 SocketSession (org.openhab.binding.russound.internal.net.SocketSession)3 Bridge (org.openhab.core.thing.Bridge)3 NeeoBrainApi (org.openhab.binding.neeo.internal.NeeoBrainApi)2 NeeoHandlerCallback (org.openhab.binding.neeo.internal.NeeoHandlerCallback)2 NeeoRoom (org.openhab.binding.neeo.internal.models.NeeoRoom)2 AbstractThingHandler (org.openhab.binding.russound.internal.rio.AbstractThingHandler)2 RioSystemHandler (org.openhab.binding.russound.internal.rio.system.RioSystemHandler)2 ThingStatusInfo (org.openhab.core.thing.ThingStatusInfo)2 ThingUID (org.openhab.core.thing.ThingUID)2 ThingBuilder (org.openhab.core.thing.binding.builder.ThingBuilder)2 Map (java.util.Map)1