Search in sources :

Example 1 with ThingHandler

use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.

the class WemoLightHandler method getWemoBridgeHandler.

private synchronized WemoBridgeHandler getWemoBridgeHandler() {
    if (this.wemoBridgeHandler == null) {
        Bridge bridge = getBridge();
        if (bridge == null) {
            logger.error("Required bridge not defined for device {}.", wemoLightID);
            return null;
        }
        ThingHandler handler = bridge.getHandler();
        if (handler instanceof WemoBridgeHandler) {
            this.wemoBridgeHandler = (WemoBridgeHandler) handler;
        } else {
            logger.debug("No available bridge handler found for {} bridge {} .", wemoLightID, bridge.getUID());
            return null;
        }
    }
    return this.wemoBridgeHandler;
}
Also used : BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 2 with ThingHandler

use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.

the class ThingManager method unregisterAndDisposeChildHandlers.

private void unregisterAndDisposeChildHandlers(Bridge bridge, ThingHandlerFactory thingHandlerFactory) {
    addThingsToBridge(bridge);
    for (Thing child : bridge.getThings()) {
        ThingHandler handler = child.getHandler();
        if (handler != null) {
            logger.debug("Unregister and dispose child '{}' of bridge '{}'.", child.getUID(), bridge.getUID());
            unregisterAndDisposeHandler(thingHandlerFactory, child, handler);
        }
    }
}
Also used : ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 3 with ThingHandler

use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.

the class ThingManager 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);
        setThingStatus(thing, buildStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_MISSING_ERROR));
        thingHandlers.remove(thing.getUID());
        thingHandlersByFactory.remove(thingHandlerFactory, thingHandler);
    }, Runnable.class).build().run();
}
Also used : ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler)

Example 4 with ThingHandler

use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.

the class ThingManager method initializeHandler.

private void initializeHandler(Thing thing) {
    if (!isHandlerRegistered(thing)) {
        return;
    }
    Lock lock = getLockForThing(thing.getUID());
    try {
        lock.lock();
        if (ThingHandlerHelper.isHandlerInitialized(thing)) {
            logger.debug("Attempt to initialize the already initialized thing '{}' will be ignored.", thing.getUID());
            return;
        }
        if (isInitializing(thing)) {
            logger.debug("Attempt to initialize a handler twice for thing '{}' at the same time will be ignored.", thing.getUID());
            return;
        }
        ThingHandler handler = thing.getHandler();
        if (handler == null) {
            throw new IllegalStateException("Handler should not be null here");
        } else {
            if (handler.getThing() != thing) {
                logger.warn("The model of {} is inconsistent [thing.getHandler().getThing() != thing]", thing.getUID());
            }
        }
        ThingType thingType = getThingType(thing);
        applyDefaultConfiguration(thing, thingType);
        if (isInitializable(thing, thingType)) {
            setThingStatus(thing, buildStatusInfo(ThingStatus.INITIALIZING, ThingStatusDetail.NONE));
            doInitializeHandler(thing.getHandler());
        } else {
            logger.debug("Thing '{}' not initializable, check required configuration parameters.", thing.getUID());
            setThingStatus(thing, buildStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_CONFIGURATION_PENDING));
        }
    } finally {
        lock.unlock();
    }
}
Also used : ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 5 with ThingHandler

use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.

the class ThingManager method replaceThing.

private ThingHandler replaceThing(Thing oldThing, Thing newThing) {
    final ThingHandler thingHandler = thingHandlers.get(newThing.getUID());
    if (oldThing != newThing) {
        this.things.remove(oldThing);
        this.things.add(newThing);
    }
    return thingHandler;
}
Also used : ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler)

Aggregations

ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)30 Thing (org.eclipse.smarthome.core.thing.Thing)14 BaseThingHandler (org.eclipse.smarthome.core.thing.binding.BaseThingHandler)12 Bridge (org.eclipse.smarthome.core.thing.Bridge)9 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)6 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)6 Test (org.junit.Test)6 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)4 ThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory)4 Command (org.eclipse.smarthome.core.types.Command)4 Semaphore (java.util.concurrent.Semaphore)3 Lock (java.util.concurrent.locks.Lock)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 Channel (org.eclipse.smarthome.core.thing.Channel)3 BaseBridgeHandler (org.eclipse.smarthome.core.thing.binding.BaseBridgeHandler)3 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 ThingStatusInfo (org.eclipse.smarthome.core.thing.ThingStatusInfo)2 MethodHandles (java.lang.invoke.MethodHandles)1