Search in sources :

Example 11 with ThingType

use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.

the class ThingManagerOSGiJavaTest method registerThingTypeProvider.

private void registerThingTypeProvider() throws Exception {
    ThingType thingType = ThingTypeBuilder.instance(THING_TYPE_UID, "label").withConfigDescriptionURI(CONFIG_DESCRIPTION_THING).withChannelDefinitions(Collections.singletonList(new ChannelDefinition("channel", CHANNEL_TYPE_UID))).build();
    ThingTypeProvider mockThingTypeProvider = mock(ThingTypeProvider.class);
    when(mockThingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(thingType);
    registerService(mockThingTypeProvider);
}
Also used : ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ThingTypeProvider(org.eclipse.smarthome.core.thing.binding.ThingTypeProvider)

Example 12 with ThingType

use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.

the class ThingPropertiesTest method setup.

@Before
public void setup() {
    ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("bindingId", "thingTypeId"), "label").withProperties(properties).build();
    thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), new Configuration());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Before(org.junit.Before)

Example 13 with ThingType

use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.

the class SystemChannelsInChannelGroupsTest method thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDefinitions.

@Test
public void thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDefinitions() throws Exception {
    // install test bundle
    Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_IN_CHANNEL_GROUPS_BUNDLE_NAME);
    assertThat(sysBundle, is(notNullValue()));
    List<ThingType> thingTypes = thingTypeProvider.getThingTypes(null).stream().filter(it -> it.getUID().getId().equals("wireless-router")).collect(Collectors.toList());
    assertThat(thingTypes.size(), is(1));
    List<ChannelGroupType> channelGroupTypes = channelTypeRegistry.getChannelGroupTypes();
    ChannelGroupType channelGroup = channelGroupTypes.stream().filter(it -> it.getUID().equals(new ChannelGroupTypeUID("SystemChannelsInChannelGroups:channelGroup"))).findFirst().get();
    assertThat(channelGroup, is(notNullValue()));
    List<ChannelDefinition> channelDefs = channelGroup.getChannelDefinitions();
    List<ChannelDefinition> myChannel = channelDefs.stream().filter(it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel")).collect(Collectors.toList());
    List<ChannelDefinition> sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr") && it.getChannelTypeUID().getAsString().equals("system:signal-strength")).collect(Collectors.toList());
    List<ChannelDefinition> lowBat = channelDefs.stream().filter(it -> it.getId().equals("lowbat") && it.getChannelTypeUID().getAsString().equals("system:low-battery")).collect(Collectors.toList());
    assertThat(myChannel.size(), is(1));
    assertThat(sigStr.size(), is(1));
    assertThat(lowBat.size(), is(1));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Collection(java.util.Collection) SyntheticBundleInstaller(org.eclipse.smarthome.test.SyntheticBundleInstaller) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Assert.assertThat(org.junit.Assert.assertThat) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) List(java.util.List) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelTypeRegistry(org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry) ThingTypeProvider(org.eclipse.smarthome.core.thing.binding.ThingTypeProvider) After(org.junit.After) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Bundle(org.osgi.framework.Bundle) Before(org.junit.Before) Bundle(org.osgi.framework.Bundle) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 14 with ThingType

use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.

the class SystemChannelsInChannelGroupsTest method systemChannelsInChannelGroupsShouldLoadAndUnload.

@Test
public void systemChannelsInChannelGroupsShouldLoadAndUnload() throws Exception {
    int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
    int initialNumberOfChannelTypes = channelTypeRegistry.getChannelTypes().size();
    int initialNumberOfChannelGroupTypes = channelTypeRegistry.getChannelGroupTypes().size();
    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_IN_CHANNEL_GROUPS_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));
    Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 1));
    assertThat(channelTypeRegistry.getChannelTypes().size(), is(initialNumberOfChannelTypes + 1));
    assertThat(channelTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes + 1));
    // uninstall test bundle
    bundle.uninstall();
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
    assertThat(thingTypeProvider.getThingTypes(null).size(), is(initialNumberOfThingTypes));
    assertThat(channelTypeRegistry.getChannelTypes().size(), is(initialNumberOfChannelTypes));
    assertThat(channelTypeRegistry.getChannelGroupTypes().size(), is(initialNumberOfChannelGroupTypes));
}
Also used : Bundle(org.osgi.framework.Bundle) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 15 with ThingType

use of org.eclipse.smarthome.core.thing.type.ThingType in project smarthome by eclipse.

the class SystemWideChannelTypesTest method systemChannelsShouldTranslateProperly.

@Test
public void systemChannelsShouldTranslateProperly() throws Exception {
    int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
    // install test bundle
    Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
    assertThat(sysBundle, is(notNullValue()));
    Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 1));
    ThingType wirelessRouterType = thingTypes.stream().filter(it -> it.getUID().getAsString().equals("SystemChannels:wireless-router")).findFirst().get();
    assertThat(wirelessRouterType, is(notNullValue()));
    List<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
    assertThat(channelDefs.size(), is(3));
    ChannelDefinition myChannel = channelDefs.stream().filter(it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel")).findFirst().get();
    assertThat(myChannel, is(notNullValue()));
    ChannelDefinition sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr") && it.getChannelTypeUID().getAsString().equals("system:signal-strength")).findFirst().get();
    assertThat(sigStr, is(notNullValue()));
    ChannelDefinition lowBat = channelDefs.stream().filter(it -> it.getId().equals("lowbat") && it.getChannelTypeUID().getAsString().equals("system:low-battery")).findFirst().get();
    assertThat(lowBat, is(notNullValue()));
    assertThat(channelTypeRegistry.getChannelType(myChannel.getChannelTypeUID(), Locale.GERMAN).getLabel(), is("Mein String My Channel"));
    assertThat(channelTypeRegistry.getChannelType(myChannel.getChannelTypeUID(), Locale.GERMAN).getDescription(), is("Wetterinformation mit My Channel Type Beschreibung"));
    assertThat(myChannel.getLabel(), is("Mein String My Channel"));
    assertThat(myChannel.getDescription(), is("Wetterinformation mit My Channel Type Beschreibung"));
    assertThat(channelTypeRegistry.getChannelType(sigStr.getChannelTypeUID(), Locale.GERMAN).getLabel(), is("Signalstärke"));
    assertThat(sigStr.getLabel(), is("Meine spezial Signalstärke"));
    assertThat(sigStr.getDescription(), is("Meine spezial Beschreibung für Signalstärke"));
    assertThat(channelTypeRegistry.getChannelType(lowBat.getChannelTypeUID(), Locale.GERMAN).getLabel(), is("Niedriger Batteriestatus"));
    assertThat(lowBat.getLabel(), is("Niedriger Batteriestatus"));
    assertThat(lowBat.getDescription(), is(nullValue()));
}
Also used : Bundle(org.osgi.framework.Bundle) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Aggregations

ThingType (org.eclipse.smarthome.core.thing.type.ThingType)26 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)15 Test (org.junit.Test)15 Bundle (org.osgi.framework.Bundle)15 ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)7 List (java.util.List)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)3 ThingTypeProvider (org.eclipse.smarthome.core.thing.binding.ThingTypeProvider)3 Before (org.junit.Before)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)2 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)2 Configuration (org.eclipse.smarthome.config.core.Configuration)2 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)2