use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.
the class CircuitHandler method getDssBridgeHandler.
private synchronized BridgeHandler getDssBridgeHandler() {
if (this.dssBridgeHandler == null) {
Bridge bridge = getBridge();
if (bridge == null) {
logger.debug("Bride cannot be found");
return null;
}
ThingHandler handler = bridge.getHandler();
if (handler instanceof BridgeHandler) {
dssBridgeHandler = (BridgeHandler) handler;
} else {
return null;
}
}
return dssBridgeHandler;
}
use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.
the class DeviceHandler method getDssBridgeHandler.
private synchronized BridgeHandler getDssBridgeHandler() {
if (this.dssBridgeHandler == null) {
Bridge bridge = getBridge();
if (bridge == null) {
logger.debug("Bride cannot be found");
return null;
}
ThingHandler handler = bridge.getHandler();
if (handler instanceof BridgeHandler) {
dssBridgeHandler = (BridgeHandler) handler;
} else {
return null;
}
}
return dssBridgeHandler;
}
use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.
the class SceneHandler method getBridgeHandler.
private synchronized BridgeHandler getBridgeHandler() {
if (this.bridgeHandler == null) {
Bridge bridge = getBridge();
if (bridge == null) {
logger.debug("Bridge cannot be found");
return null;
}
ThingHandler handler = bridge.getHandler();
if (handler instanceof BridgeHandler) {
this.bridgeHandler = (BridgeHandler) handler;
} else {
logger.debug("BridgeHandler cannot be found");
return null;
}
}
return this.bridgeHandler;
}
use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.
the class AbstractDmxThingTest method assertThingStatus.
protected void assertThingStatus(Thing thing) {
// check that thing turns online if properly configured
waitForAssert(() -> assertEquals(ThingStatus.ONLINE, thing.getStatusInfo().getStatus()));
// check that thing properly follows bridge status
ThingHandler handler = thing.getHandler();
assertNotNull(handler);
handler.bridgeStatusChanged(ThingStatusInfoBuilder.create(ThingStatus.OFFLINE).build());
waitForAssert(() -> assertEquals(ThingStatus.OFFLINE, thing.getStatusInfo().getStatus()));
handler.bridgeStatusChanged(ThingStatusInfoBuilder.create(ThingStatus.ONLINE).build());
waitForAssert(() -> assertEquals(ThingStatus.ONLINE, thing.getStatusInfo().getStatus()));
}
use of org.eclipse.smarthome.core.thing.binding.ThingHandler in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method testInitializeCallsThingUpdated.
@Test
public void testInitializeCallsThingUpdated() throws Exception {
registerThingTypeProvider();
AtomicReference<ThingHandlerCallback> thc = new AtomicReference<>();
AtomicReference<Boolean> initializeRunning = new AtomicReference<>(false);
registerThingHandlerFactory(THING_TYPE_UID, thing -> {
ThingHandler mockHandler = mock(ThingHandler.class);
doAnswer(a -> {
thc.set((ThingHandlerCallback) a.getArguments()[0]);
return null;
}).when(mockHandler).setCallback(ArgumentMatchers.isA(ThingHandlerCallback.class));
doAnswer(a -> {
initializeRunning.set(true);
// call thingUpdated() from within initialize()
thc.get().thingUpdated(THING);
// hang on a little to provoke a potential dead-lock
Thread.sleep(1000);
initializeRunning.set(false);
return null;
}).when(mockHandler).initialize();
when(mockHandler.getThing()).thenReturn(THING);
return mockHandler;
});
new Thread((Runnable) () -> managedThingProvider.add(THING)).start();
waitForAssert(() -> {
assertThat(THING.getStatus(), is(ThingStatus.INITIALIZING));
});
// ensure it didn't run into a dead-lock which gets resolved by the SafeCaller.
waitForAssert(() -> {
assertThat(initializeRunning.get(), is(false));
}, SafeCaller.DEFAULT_TIMEOUT - 100, 50);
}
Aggregations