Search in sources :

Example 1 with ThingStatusDetail

use of org.eclipse.smarthome.core.thing.ThingStatusDetail in project smarthome by eclipse.

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.eclipse.smarthome.core.thing.ThingStatusDetail) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler)

Example 2 with ThingStatusDetail

use of org.eclipse.smarthome.core.thing.ThingStatusDetail in project smarthome by eclipse.

the class HomematicThingHandler method updateStatus.

/**
 * Updates the thing status based on device status.
 */
private void updateStatus(HmDevice device) throws GatewayNotAvailableException, IOException {
    loadHomematicChannelValues(device.getChannel(0));
    ThingStatus oldStatus = thing.getStatus();
    ThingStatus newStatus = ThingStatus.ONLINE;
    ThingStatusDetail newDetail = ThingStatusDetail.NONE;
    if (getBridge().getStatus() == ThingStatus.OFFLINE) {
        newStatus = ThingStatus.OFFLINE;
        newDetail = ThingStatusDetail.BRIDGE_OFFLINE;
    } else if (device.isFirmwareUpdating()) {
        newStatus = ThingStatus.OFFLINE;
        newDetail = ThingStatusDetail.FIRMWARE_UPDATING;
    } else if (device.isUnreach()) {
        newStatus = ThingStatus.OFFLINE;
        newDetail = ThingStatusDetail.COMMUNICATION_ERROR;
    } else if (device.isConfigPending() || device.isUpdatePending()) {
        newDetail = ThingStatusDetail.CONFIGURATION_PENDING;
    }
    if (thing.getStatus() != newStatus || thing.getStatusInfo().getStatusDetail() != newDetail) {
        updateStatus(newStatus, newDetail);
    }
    if (oldStatus == ThingStatus.OFFLINE && newStatus == ThingStatus.ONLINE) {
        initialize();
    }
}
Also used : ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) ThingStatusDetail(org.eclipse.smarthome.core.thing.ThingStatusDetail)

Aggregations

ThingStatusDetail (org.eclipse.smarthome.core.thing.ThingStatusDetail)2 ThingStatus (org.eclipse.smarthome.core.thing.ThingStatus)1 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)1