Search in sources :

Example 11 with ThingHandler

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;
}
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 12 with ThingHandler

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;
}
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 13 with ThingHandler

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;
}
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 14 with ThingHandler

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

Example 15 with ThingHandler

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);
}
Also used : ThingHandlerCallback(org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback) AtomicReference(java.util.concurrent.atomic.AtomicReference) BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

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