Search in sources :

Example 1 with ThingTypeRegistry

use of org.openhab.core.thing.type.ThingTypeRegistry in project openhab-core by openhab.

the class BindingBaseClassesOSGiTest method registerThingTypeAndConfigDescription.

private void registerThingTypeAndConfigDescription() {
    ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID(BINDING_ID, THING_TYPE_ID), "label").withConfigDescriptionURI(BINDING_CONFIG_URI).build();
    ConfigDescription configDescription = ConfigDescriptionBuilder.create(BINDING_CONFIG_URI).withParameter(ConfigDescriptionParameterBuilder.create("parameter", ConfigDescriptionParameter.Type.TEXT).withRequired(true).build()).build();
    ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
    when(thingTypeProvider.getThingType(ArgumentMatchers.any(ThingTypeUID.class), ArgumentMatchers.any(Locale.class))).thenReturn(thingType);
    registerService(thingTypeProvider);
    ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
    when(thingTypeRegistry.getThingType(ArgumentMatchers.any(ThingTypeUID.class))).thenReturn(thingType);
    registerService(thingTypeRegistry);
    ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
    when(configDescriptionProvider.getConfigDescription(ArgumentMatchers.any(URI.class), ArgumentMatchers.nullable(Locale.class))).thenReturn(configDescription);
    registerService(configDescriptionProvider);
}
Also used : Locale(java.util.Locale) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ThingType(org.openhab.core.thing.type.ThingType) URI(java.net.URI) ConfigDescriptionProvider(org.openhab.core.config.core.ConfigDescriptionProvider)

Example 2 with ThingTypeRegistry

use of org.openhab.core.thing.type.ThingTypeRegistry in project openhab-core by openhab.

the class BindingBaseClassesOSGiTest method registerThingTypeProvider.

private void registerThingTypeProvider() {
    ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID(BINDING_ID, THING_TYPE_ID), "label").withConfigDescriptionURI(BINDING_CONFIG_URI).build();
    ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
    when(thingTypeProvider.getThingType(ArgumentMatchers.any(ThingTypeUID.class), ArgumentMatchers.nullable(Locale.class))).thenReturn(thingType);
    registerService(thingTypeProvider);
    ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
    when(thingTypeRegistry.getThingType(ArgumentMatchers.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)

Example 3 with ThingTypeRegistry

use of org.openhab.core.thing.type.ThingTypeRegistry in project openhab-core by openhab.

the class ChangeThingTypeOSGiTest method setup.

@BeforeEach
public void setup() throws URISyntaxException {
    registerVolatileStorageService();
    managedThingProvider = getService(ManagedThingProvider.class);
    assertThat(managedThingProvider, is(notNullValue()));
    configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
    assertThat(configDescriptionRegistry, is(notNullValue()));
    managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertThat(managedItemChannelLinkProvider, is(notNullValue()));
    managedItemProvider = getService(ManagedItemProvider.class);
    assertThat(managedItemProvider, is(notNullValue()));
    ComponentContext componentContext = mock(ComponentContext.class);
    when(componentContext.getBundleContext()).thenReturn(bundleContext);
    thingHandlerFactory = new SampleThingHandlerFactory();
    thingHandlerFactory.activate(componentContext);
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
    Map<String, String> thingTypeGenericProperties = Map.ofEntries(entry(PROPERTY_ON_GENERIC_THING_TYPE, GENERIC_VALUE), entry(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, GENERIC_VALUE));
    Map<String, String> thingTypeSpecificProperties = Map.ofEntries(entry(PROPERTY_ON_SPECIFIC_THING_TYPE, SPECIFIC_VALUE), entry(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, SPECIFIC_VALUE));
    thingTypeGeneric = registerThingTypeAndConfigDescription(THING_TYPE_GENERIC_UID, thingTypeGenericProperties);
    thingTypeSpecific = registerThingTypeAndConfigDescription(THING_TYPE_SPECIFIC_UID, thingTypeSpecificProperties);
    ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
    when(thingTypeProvider.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
    registerService(thingTypeProvider);
    ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
    when(thingTypeRegistry.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
    registerService(thingTypeRegistry);
    ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
    when(configDescriptionProvider.getConfigDescription(any(), any())).thenAnswer(invocation -> configDescriptions.get(invocation.getArgument(0)));
    registerService(configDescriptionProvider);
    ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
    when(channelTypeProvider.getChannelTypes(any())).thenReturn(channelTypes.values());
    when(channelTypeProvider.getChannelType(any(), any())).thenAnswer(invocation -> channelTypes.get(invocation.getArgument(0)));
    registerService(channelTypeProvider);
    ChannelGroupTypeProvider channelGroupTypeProvider = mock(ChannelGroupTypeProvider.class);
    when(channelGroupTypeProvider.getChannelGroupTypes(any())).thenReturn(channelGroupTypes.values());
    when(channelGroupTypeProvider.getChannelGroupType(any(), any())).thenAnswer(invocation -> channelGroupTypes.get(invocation.getArgument(0)));
    registerService(channelGroupTypeProvider);
    managedItemProvider.add(new StringItem(ITEM_GENERIC));
    managedItemProvider.add(new StringItem(ITEM_SPECIFIC));
    managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_GENERIC);
    managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_SPECIFIC);
}
Also used : ManagedItemProvider(org.openhab.core.items.ManagedItemProvider) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ComponentContext(org.osgi.service.component.ComponentContext) StringItem(org.openhab.core.library.items.StringItem) ChannelGroupTypeProvider(org.openhab.core.thing.type.ChannelGroupTypeProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) ConfigDescriptionRegistry(org.openhab.core.config.core.ConfigDescriptionRegistry) ConfigDescriptionProvider(org.openhab.core.config.core.ConfigDescriptionProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ThingTypeRegistry

use of org.openhab.core.thing.type.ThingTypeRegistry 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(this::unregisterService);
}
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 5 with ThingTypeRegistry

use of org.openhab.core.thing.type.ThingTypeRegistry in project openhab-addons by openhab.

the class AbstractMieleThingHandlerTest method createChannelsForThingHandler.

private List<Channel> createChannelsForThingHandler(ThingTypeUID thingTypeUid, ThingUID thingUid) {
    ChannelTypeRegistry channelTypeRegistry = getService(ChannelTypeRegistry.class, ChannelTypeRegistry.class);
    assertNotNull(channelTypeRegistry);
    ThingTypeRegistry thingTypeRegistry = getService(ThingTypeRegistry.class, ThingTypeRegistry.class);
    assertNotNull(thingTypeRegistry);
    ThingType thingType = thingTypeRegistry.getThingType(thingTypeUid);
    assertNotNull(thingType);
    List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
    assertNotNull(channelDefinitions);
    List<Channel> channels = new ArrayList<Channel>();
    for (ChannelDefinition channelDefinition : channelDefinitions) {
        ChannelTypeUID channelTypeUid = channelDefinition.getChannelTypeUID();
        assertNotNull(channelTypeUid);
        ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUid);
        assertNotNull(channelType);
        String acceptedItemType = channelType.getItemType();
        assertNotNull(acceptedItemType);
        String channelId = channelDefinition.getId();
        assertNotNull(channelId);
        ChannelUID channelUid = new ChannelUID(thingUid, channelId);
        assertNotNull(channelUid);
        Channel channel = ChannelBuilder.create(channelUid, acceptedItemType).build();
        assertNotNull(channel);
        channels.add(channel);
    }
    return channels;
}
Also used : ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) ArrayList(java.util.ArrayList) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ThingType(org.openhab.core.thing.type.ThingType) ChannelType(org.openhab.core.thing.type.ChannelType)

Aggregations

ThingTypeRegistry (org.openhab.core.thing.type.ThingTypeRegistry)7 ThingType (org.openhab.core.thing.type.ThingType)5 Locale (java.util.Locale)4 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)4 ConfigDescriptionProvider (org.openhab.core.config.core.ConfigDescriptionProvider)3 URI (java.net.URI)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ConfigDescription (org.openhab.core.config.core.ConfigDescription)2 ConfigDescriptionRegistry (org.openhab.core.config.core.ConfigDescriptionRegistry)2 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)2 ThingTypeProvider (org.openhab.core.thing.binding.ThingTypeProvider)2 ManagedItemChannelLinkProvider (org.openhab.core.thing.link.ManagedItemChannelLinkProvider)2 ChannelTypeRegistry (org.openhab.core.thing.type.ChannelTypeRegistry)2 ComponentContext (org.osgi.service.component.ComponentContext)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Test (org.junit.jupiter.api.Test)1