Search in sources :

Example 1 with ThingTypeProvider

use of org.openhab.core.thing.binding.ThingTypeProvider in project openhab-core by openhab.

the class InboxOSGiTest method assertThatApproveAddsPropertiesOfDiscoveryResultWhichAreConfigDescriptionParametersAsThingConfigurationPropertiesAndPropertiesWhichAreNoConfigDescriptionParametersAsThingProperties.

@Test
@SuppressWarnings("null")
public void assertThatApproveAddsPropertiesOfDiscoveryResultWhichAreConfigDescriptionParametersAsThingConfigurationPropertiesAndPropertiesWhichAreNoConfigDescriptionParametersAsThingProperties() {
    final List<Object> services = new LinkedList<>();
    inbox.add(testDiscoveryResult);
    final ThingTypeProvider thingTypeProvider = new ThingTypeProvider() {

        @Override
        public Collection<ThingType> getThingTypes(@Nullable Locale locale) {
            return Set.of(testThingType);
        }

        @Override
        @Nullable
        public ThingType getThingType(ThingTypeUID thingTypeUID, @Nullable Locale locale) {
            return thingTypeUID.equals(testThingType.getUID()) ? testThingType : null;
        }
    };
    services.add(registerService(thingTypeProvider));
    final ThingTypeRegistry thingTypeRegistry = getService(ThingTypeRegistry.class);
    assertNotNull(thingTypeRegistry);
    waitForAssert(() -> assertNotNull(thingTypeRegistry.getThingType(testThingType.getUID())));
    final ConfigDescriptionProvider configDescriptionProvider = new ConfigDescriptionProvider() {

        @Override
        public Collection<ConfigDescription> getConfigDescriptions(@Nullable Locale locale) {
            return Set.of(testConfigDescription);
        }

        @Override
        @Nullable
        public ConfigDescription getConfigDescription(URI uri, @Nullable Locale locale) {
            return uri.equals(testConfigDescription.getUID()) ? testConfigDescription : null;
        }
    };
    services.add(registerService(configDescriptionProvider));
    final ConfigDescriptionRegistry configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
    assertNotNull(configDescriptionRegistry);
    waitForAssert(() -> assertNotNull(configDescriptionRegistry.getConfigDescription(testConfigDescription.getUID())));
    Thing approvedThing = inbox.approve(testThing.getUID(), testThingLabel, null);
    Thing addedThing = registry.get(testThing.getUID());
    assertTrue(approvedThing.equals(addedThing));
    assertFalse(addedThing == null);
    for (String key : keysInConfigDescription) {
        Object thingConfItem = addedThing.getConfiguration().get(key);
        Object descResultParam = discoveryResultProperties.get(key);
        if (descResultParam instanceof Number) {
            descResultParam = new BigDecimal(descResultParam.toString());
        }
        assertFalse(thingConfItem == null);
        assertFalse(descResultParam == null);
        assertTrue(thingConfItem.equals(descResultParam));
    }
    for (String key : keysNotInConfigDescription) {
        String thingProperty = addedThing.getProperties().get(key);
        String descResultParam = String.valueOf(discoveryResultProperties.get(key));
        assertFalse(thingProperty == null);
        assertFalse(descResultParam == null);
        assertTrue(thingProperty.equals(descResultParam));
    }
    services.forEach(obj -> unregisterService(obj));
}
Also used : Locale(java.util.Locale) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ThingType(org.openhab.core.thing.type.ThingType) URI(java.net.URI) LinkedList(java.util.LinkedList) BigDecimal(java.math.BigDecimal) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ConfigDescriptionRegistry(org.openhab.core.config.core.ConfigDescriptionRegistry) ThingTypeProvider(org.openhab.core.thing.binding.ThingTypeProvider) Nullable(org.eclipse.jdt.annotation.Nullable) ConfigDescriptionProvider(org.openhab.core.config.core.ConfigDescriptionProvider) Thing(org.openhab.core.thing.Thing) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 2 with ThingTypeProvider

use of org.openhab.core.thing.binding.ThingTypeProvider in project openhab-core by openhab.

the class DynamicThingUpdateOSGiTest method setUp.

@BeforeEach
public void setUp() {
    registerVolatileStorageService();
    ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
    when(thingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(THING_TYPE);
    registerService(thingTypeProvider);
    inbox = getService(Inbox.class);
    managedThingProvider = getService(ManagedThingProvider.class);
    assertEquals(0, inbox.getAll().size());
    ThingHandlerFactory thingHandlerFactory = createThingHandlerFactory();
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
}
Also used : ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ThingTypeProvider(org.openhab.core.thing.binding.ThingTypeProvider) ThingHandlerFactory(org.openhab.core.thing.binding.ThingHandlerFactory) BaseThingHandlerFactory(org.openhab.core.thing.binding.BaseThingHandlerFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ThingTypeProvider

use of org.openhab.core.thing.binding.ThingTypeProvider in project openhab-core by openhab.

the class ThingManagerOSGiJavaTest method registerThingTypeProvider.

private void registerThingTypeProvider() throws Exception {
    ThingType thingType = ThingTypeBuilder.instance(THING_TYPE_UID, "label").withConfigDescriptionURI(configDescriptionThing).withChannelDefinitions(List.of(new ChannelDefinitionBuilder(CHANNEL_ID, CHANNEL_TYPE_UID).build())).build();
    ThingTypeProvider mockThingTypeProvider = mock(ThingTypeProvider.class);
    when(mockThingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(thingType);
    registerService(mockThingTypeProvider);
}
Also used : ChannelDefinitionBuilder(org.openhab.core.thing.type.ChannelDefinitionBuilder) ThingType(org.openhab.core.thing.type.ThingType) ThingTypeProvider(org.openhab.core.thing.binding.ThingTypeProvider)

Example 4 with ThingTypeProvider

use of org.openhab.core.thing.binding.ThingTypeProvider in project openhab-core by openhab.

the class ThingManagerOSGiTest method registerThingTypeProvider.

private void registerThingTypeProvider() {
    ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("binding", "type"), "label").withConfigDescriptionURI(THING_CONFIG_URI).build();
    ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
    when(thingTypeProvider.getThingType(any(ThingTypeUID.class), nullable(Locale.class))).thenReturn(thingType);
    registerService(thingTypeProvider);
    ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
    when(thingTypeRegistry.getThingType(any(ThingTypeUID.class))).thenReturn(thingType);
    registerService(thingTypeRegistry);
}
Also used : Locale(java.util.Locale) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ThingType(org.openhab.core.thing.type.ThingType) ThingTypeProvider(org.openhab.core.thing.binding.ThingTypeProvider)

Example 5 with ThingTypeProvider

use of org.openhab.core.thing.binding.ThingTypeProvider in project openhab-core by openhab.

the class SystemWideChannelTypesTest method setUp.

@BeforeEach
public void setUp() {
    thingTypeProvider = getService(ThingTypeProvider.class);
    assertThat(thingTypeProvider, is(notNullValue()));
    channelTypeRegistry = getService(ChannelTypeRegistry.class);
    assertThat(channelTypeRegistry, is(notNullValue()));
    ChannelTypeProvider provider = getService(ChannelTypeProvider.class, DefaultSystemChannelTypeProvider.class);
    assertTrue(provider instanceof DefaultSystemChannelTypeProvider);
    systemChannelTypeProvider = provider;
}
Also used : DefaultSystemChannelTypeProvider(org.openhab.core.thing.DefaultSystemChannelTypeProvider) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) DefaultSystemChannelTypeProvider(org.openhab.core.thing.DefaultSystemChannelTypeProvider) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) ThingTypeProvider(org.openhab.core.thing.binding.ThingTypeProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ThingTypeProvider (org.openhab.core.thing.binding.ThingTypeProvider)5 ThingType (org.openhab.core.thing.type.ThingType)3 Locale (java.util.Locale)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)2 ThingTypeRegistry (org.openhab.core.thing.type.ThingTypeRegistry)2 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 LinkedList (java.util.LinkedList)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Test (org.junit.jupiter.api.Test)1 ConfigDescription (org.openhab.core.config.core.ConfigDescription)1 ConfigDescriptionProvider (org.openhab.core.config.core.ConfigDescriptionProvider)1 ConfigDescriptionRegistry (org.openhab.core.config.core.ConfigDescriptionRegistry)1 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)1 DefaultSystemChannelTypeProvider (org.openhab.core.thing.DefaultSystemChannelTypeProvider)1 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)1 Thing (org.openhab.core.thing.Thing)1 BaseThingHandlerFactory (org.openhab.core.thing.binding.BaseThingHandlerFactory)1 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)1