Search in sources :

Example 11 with ThingType

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

the class ThingFactoryTest method createSimpleThing.

@Test
public void createSimpleThing() {
    ThingType thingType = ThingTypeBuilder.instance("bindingId", "thingTypeId", "label").build();
    Configuration configuration = new Configuration();
    Thing thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), configuration);
    assertThat(thing.getUID().toString(), is(equalTo("bindingId:thingTypeId:thingId")));
    assertThat(thing.getThingTypeUID().toString(), is(equalTo("bindingId:thingTypeId")));
    assertThat(thing.getConfiguration(), is(not(nullValue())));
    assertThat(thing.getProperties(), is(not(nullValue())));
}
Also used : Configuration(org.openhab.core.config.core.Configuration) ThingUID(org.openhab.core.thing.ThingUID) ThingType(org.openhab.core.thing.type.ThingType) Thing(org.openhab.core.thing.Thing) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 12 with ThingType

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

the class ThingFactoryTest method createThingWithDefaultValues.

@Test
public void createThingWithDefaultValues() throws Exception {
    ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("myThingType", "myThing"), "label").withDescription("description").withChannelDefinitions(getChannelDefinitions()).withConfigDescriptionURI(new URI("scheme", "thingType", null)).build();
    Configuration configuration = new Configuration();
    ConfigDescriptionRegistry configDescriptionRegistry = mock(ConfigDescriptionRegistry.class);
    when(configDescriptionRegistry.getConfigDescription(any(URI.class))).thenAnswer(new Answer<ConfigDescription>() {

        @Override
        @Nullable
        public ConfigDescription answer(InvocationOnMock invocation) throws Throwable {
            URI uri = (URI) invocation.getArgument(0);
            return ConfigDescriptionBuilder.create(uri).withParameter(ConfigDescriptionParameterBuilder.create("testProperty", ConfigDescriptionParameter.Type.TEXT).withContext("context").withDefault("default").withDescription("description").withLimitToOptions(true).build()).build();
        }
    });
    Thing thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), configuration, null, configDescriptionRegistry);
    assertThat(thing.getConfiguration(), is(not(nullValue())));
    assertThat(thing.getConfiguration().get("testProperty"), is(not(nullValue())));
    assertThat(thing.getConfiguration().get("testProperty"), is(equalTo("default")));
    assertThat(thing.getChannels().size(), is(equalTo(2)));
    assertThat(thing.getChannels().get(0).getConfiguration().get("testProperty"), is(equalTo("default")));
    assertThat(thing.getChannels().get(1).getConfiguration().get("testProperty"), is(equalTo("default")));
    assertThat(thing.getProperties().size(), is(0));
}
Also used : Configuration(org.openhab.core.config.core.Configuration) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ThingType(org.openhab.core.thing.type.ThingType) URI(java.net.URI) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ThingUID(org.openhab.core.thing.ThingUID) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ConfigDescriptionRegistry(org.openhab.core.config.core.ConfigDescriptionRegistry) Nullable(org.eclipse.jdt.annotation.Nullable) Thing(org.openhab.core.thing.Thing) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 13 with ThingType

use of org.openhab.core.thing.type.ThingType 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 14 with ThingType

use of org.openhab.core.thing.type.ThingType 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 15 with ThingType

use of org.openhab.core.thing.type.ThingType 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)

Aggregations

ThingType (org.openhab.core.thing.type.ThingType)52 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)22 Test (org.junit.jupiter.api.Test)21 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)20 Thing (org.openhab.core.thing.Thing)18 ThingUID (org.openhab.core.thing.ThingUID)17 Configuration (org.openhab.core.config.core.Configuration)15 ChannelDefinition (org.openhab.core.thing.type.ChannelDefinition)14 URI (java.net.URI)10 ArrayList (java.util.ArrayList)9 ChannelGroupType (org.openhab.core.thing.type.ChannelGroupType)9 ChannelType (org.openhab.core.thing.type.ChannelType)9 List (java.util.List)8 Nullable (org.eclipse.jdt.annotation.Nullable)8 ConfigDescription (org.openhab.core.config.core.ConfigDescription)8 ChannelGroupDefinition (org.openhab.core.thing.type.ChannelGroupDefinition)7 ThingTypeRegistry (org.openhab.core.thing.type.ThingTypeRegistry)7 Locale (java.util.Locale)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ThingTypeProvider (org.openhab.core.thing.binding.ThingTypeProvider)6