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;
}
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);
}
}
}
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();
}
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();
}
}
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;
}
Aggregations