org.eclipse.smarthome.core.thing.binding.BaseThingHandler Java Examples

The following examples show how to use org.eclipse.smarthome.core.thing.binding.BaseThingHandler. 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: GenericThingProviderTest4.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    registerVolatileStorageService();

    readyService = getService(ReadyService.class);
    assertThat(readyService, is(notNullValue()));
    thingRegistry = getService(ThingRegistry.class);
    assertThat(thingRegistry, is(notNullValue()));
    modelRepository = getService(ModelRepository.class);
    assertThat(modelRepository, is(notNullValue()));
    modelRepository.removeModel(TESTMODEL_NAME);

    ComponentContext componentContextMock = mock(ComponentContext.class);
    when(componentContextMock.getBundleContext()).thenReturn(bundleContext);

    hueThingHandlerFactory = new TestHueThingHandlerFactoryX(componentContextMock) {
        @Override
        protected ThingHandler createHandler(final Thing thing) {
            if (thing instanceof Bridge) {
                return new TestBridgeHandler((Bridge) thing);
            } else {
                return new BaseThingHandler(thing) {
                    @Override
                    public void handleCommand(ChannelUID arg0, Command arg1) {
                    };

                    @Override
                    public void initialize() {
                        updateStatus(ThingStatus.ONLINE);
                    }
                };
            }
        }
    };

    finished = false;
    bundle = FrameworkUtil.getBundle(TestHueThingHandlerFactoryX.class);

    removeReadyMarker();
}
 
Example #2
Source File: ChannelStateDescriptionProviderOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ThingHandler createHandler(Thing thing) {
    return new BaseThingHandler(thing) {
        @Override
        public void handleCommand(ChannelUID channelUID, Command command) {
        }

        @Override
        public void initialize() {
            updateStatus(ThingStatus.ONLINE);
        }
    };
}
 
Example #3
Source File: ThingManagerOSGiJavaTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInitializeOnlyIfInitializable() throws Exception {
    registerThingTypeProvider();
    registerChannelTypeProvider();
    registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) {
        @Override
        public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
        }
    });

    ConfigDescriptionProvider mockConfigDescriptionProvider = mock(ConfigDescriptionProvider.class);
    List<ConfigDescriptionParameter> parameters = Collections.singletonList( //
            ConfigDescriptionParameterBuilder.create(CONFIG_PARAM_NAME, Type.TEXT).withRequired(true).build() //
    );
    registerService(mockConfigDescriptionProvider, ConfigDescriptionProvider.class.getName());

    // verify a missing mandatory thing config prevents it from getting initialized
    when(mockConfigDescriptionProvider.getConfigDescription(eq(CONFIG_DESCRIPTION_THING), any()))
            .thenReturn(new ConfigDescription(CONFIG_DESCRIPTION_THING, parameters));
    assertThingStatus(Collections.emptyMap(), Collections.emptyMap(), ThingStatus.UNINITIALIZED,
            ThingStatusDetail.HANDLER_CONFIGURATION_PENDING);

    // verify a missing mandatory channel config prevents it from getting initialized
    when(mockConfigDescriptionProvider.getConfigDescription(eq(CONFIG_DESCRIPTION_CHANNEL), any()))
            .thenReturn(new ConfigDescription(CONFIG_DESCRIPTION_CHANNEL, parameters));
    assertThingStatus(Collections.singletonMap(CONFIG_PARAM_NAME, "value"), Collections.emptyMap(),
            ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_CONFIGURATION_PENDING);

    // verify a satisfied config does not prevent it from getting initialized anymore
    assertThingStatus(Collections.singletonMap(CONFIG_PARAM_NAME, "value"),
            Collections.singletonMap(CONFIG_PARAM_NAME, "value"), ThingStatus.ONLINE, ThingStatusDetail.NONE);
}