Java Code Examples for org.eclipse.smarthome.core.thing.binding.ThingHandler#setCallback()
The following examples show how to use
org.eclipse.smarthome.core.thing.binding.ThingHandler#setCallback() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThingManagerImpl.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void doRegisterHandler(final Thing thing, final ThingHandlerFactory thingHandlerFactory) { logger.debug("Calling '{}.registerHandler()' for thing '{}'.", thingHandlerFactory.getClass().getSimpleName(), thing.getUID()); try { ThingHandler thingHandler = thingHandlerFactory.registerHandler(thing); thingHandler.setCallback(ThingManagerImpl.this.thingHandlerCallback); thing.setHandler(thingHandler); thingHandlers.put(thing.getUID(), thingHandler); synchronized (thingHandlersByFactory) { thingHandlersByFactory.computeIfAbsent(thingHandlerFactory, unused -> new HashSet<>()) .add(thingHandler); } } catch (Exception ex) { ThingStatusInfo statusInfo = buildStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_REGISTERING_ERROR, ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage()); setThingStatus(thing, statusInfo); logger.error("Exception occurred while calling thing handler factory '{}': {}", thingHandlerFactory, ex.getMessage(), ex); } }
Example 2
Source File: AstroValidConfigurationTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void assertThingStatus(Configuration configuration, ThingStatus expectedStatus) { ThingUID thingUID = new ThingUID(THING_TYPE_SUN, TEST_SUN_THING_ID); Thing thing = mock(Thing.class); when(thing.getConfiguration()).thenReturn(configuration); when(thing.getUID()).thenReturn(thingUID); ThingHandlerCallback callback = mock(ThingHandlerCallback.class); CronScheduler cronScheduler = mock(CronScheduler.class); ThingHandler sunHandler = new SunHandler(thing, cronScheduler); sunHandler.setCallback(callback); sunHandler.initialize(); ThingStatusInfo expectedThingStatus = new ThingStatusInfo(expectedStatus, ThingStatusDetail.NONE, null); verify(callback, times(1)).statusUpdated(thing, expectedThingStatus); }
Example 3
Source File: AbstractDmxThingTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
protected void assertThingStatusWithoutBridge(ThingHandler handler) { handler.setCallback(mockCallback); handler.initialize(); waitForAssert(() -> { assertEquals(ThingStatus.OFFLINE, handler.getThing().getStatus()); assertEquals(ThingStatusDetail.CONFIGURATION_ERROR, handler.getThing().getStatusInfo().getStatusDetail()); }); }
Example 4
Source File: AbstractDmxThingTest.java From smarthome with Eclipse Public License 2.0 | 4 votes |
protected void initializeHandler(ThingHandler handler) { handler.getThing().setHandler(handler); handler.setCallback(mockCallback); handler.initialize(); }