Search in sources :

Example 6 with ChannelType

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

the class ThingTypesTest method thingTypesShouldLoad.

@Test
public void thingTypesShouldLoad() throws Exception {
    int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));
    Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 3));
    BridgeType bridgeType = (BridgeType) thingTypes.stream().filter(it -> it.toString().equals("hue:bridge")).findFirst().get();
    assertThat(bridgeType, is(notNullValue()));
    assertThat(bridgeType.getCategory(), is("NetworkAppliance"));
    assertThat(bridgeType.isListed(), is(false));
    assertThat(bridgeType.getLabel(), is("HUE Bridge"));
    assertThat(bridgeType.getDescription(), is("The hue Bridge represents the Philips hue bridge."));
    assertThat(bridgeType.getProperties().size(), is(1));
    assertThat(bridgeType.getProperties().get("vendor"), is("Philips"));
    assertThat(bridgeType.getRepresentationProperty(), is("serialNumber"));
    ThingType thingType = thingTypes.stream().filter(it -> it.toString().equals("hue:lamp")).findFirst().get();
    assertThat(thingType, is(notNullValue()));
    assertThat(thingType.getCategory(), is("Lightbulb"));
    assertThat(thingType.isListed(), is(false));
    assertThat(thingType.getLabel(), is("HUE Lamp"));
    assertThat(thingType.getDescription(), is("My own great HUE Lamp."));
    assertThat(thingType.getSupportedBridgeTypeUIDs().size(), is(1));
    assertThat(thingType.getSupportedBridgeTypeUIDs().get(0), is("hue:bridge"));
    assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("alarm", "brightness"));
    assertThat(thingType.getProperties().size(), is(2));
    assertThat(thingType.getProperties().get("key1"), is("value1"));
    assertThat(thingType.getProperties().get("key2"), is("value2"));
    assertThat(thingType.getRepresentationProperty(), is("uniqueId"));
    List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
    assertThat(channelDefinitions.size(), is(3));
    ChannelDefinition colorChannel = channelDefinitions.stream().filter(it -> it.getId().equals("color")).findFirst().get();
    assertThat(colorChannel, is(notNullValue()));
    assertThat(colorChannel.getProperties().size(), is(2));
    assertThat(colorChannel.getProperties().get("chan.key1"), is("value1"));
    assertThat(colorChannel.getProperties().get("chan.key2"), is("value2"));
    ChannelType colorChannelType = channelTypeRegistry.getChannelType(colorChannel.getChannelTypeUID());
    assertThat(colorChannelType, is(notNullValue()));
    assertThat(colorChannelType.toString(), is("hue:color"));
    assertThat(colorChannelType.getItemType(), is("ColorItem"));
    assertThat(colorChannelType.getLabel(), is("HUE Lamp Color"));
    assertThat(colorChannelType.getDescription(), is("The color channel allows to control the color of the hue lamp. It is also possible to dim values and switch the lamp on and off."));
    Set<String> tags = colorChannelType.getTags();
    assertThat(tags, is(notNullValue()));
    assertThat(tags.contains("Hue"), is(true));
    assertThat(tags.contains("ColorLamp"), is(true));
    assertThat(tags.contains("AmbientLamp"), is(false));
    assertThat(tags.contains("AlarmSystem"), is(false));
    ChannelDefinition colorTemperatureChannel = channelDefinitions.stream().filter(it -> it.getId().equals("color_temperature")).findFirst().get();
    assertThat(colorTemperatureChannel, is(notNullValue()));
    assertThat(colorTemperatureChannel.getProperties().size(), is(0));
    ChannelType colorTemperatureChannelType = channelTypeRegistry.getChannelType(colorTemperatureChannel.getChannelTypeUID());
    assertThat(colorTemperatureChannelType, is(notNullValue()));
    assertThat(colorTemperatureChannelType.toString(), is("hue:color_temperature"));
    assertThat(colorTemperatureChannelType.getItemType(), is("DimmerItem"));
    assertThat(colorTemperatureChannelType.getLabel(), is("HUE Lamp Color Temperature"));
    assertThat(colorTemperatureChannelType.getDescription(), is("The color temperature channel allows to set the color temperature from 0 (cold) to 100 (warm)."));
    tags = colorTemperatureChannelType.getTags();
    assertThat(tags, is(notNullValue()));
    assertThat(tags.contains("Hue"), is(true));
    assertThat(tags.contains("AmbientLamp"), is(true));
    assertThat(tags.contains("ColorLamp"), is(false));
    assertThat(tags.contains("AlarmSystem"), is(false));
    ChannelDefinition alarmChannel = channelDefinitions.stream().filter(it -> it.getId().equals("alarm")).findFirst().get();
    assertThat(alarmChannel, is(notNullValue()));
    ChannelType alarmChannelType = channelTypeRegistry.getChannelType(alarmChannel.getChannelTypeUID());
    assertThat(alarmChannelType, is(notNullValue()));
    assertThat(alarmChannelType.toString(), is("hue:alarm"));
    assertThat(alarmChannelType.getItemType(), is("Number"));
    assertThat(alarmChannelType.getLabel(), is("Alarm System"));
    assertThat(alarmChannelType.getDescription(), is("The light blinks if alarm is set."));
    tags = alarmChannelType.getTags();
    assertThat(tags, is(notNullValue()));
    assertThat(tags.contains("Hue"), is(true));
    assertThat(tags.contains("AlarmSystem"), is(true));
    assertThat(tags.contains("AmbientLamp"), is(false));
    assertThat(tags.contains("ColorLamp"), is(false));
    assertThat(alarmChannelType.getCategory(), is(equalTo("ALARM")));
    StateDescription state = alarmChannelType.getState();
    assertThat(state.getMinimum(), is(BigDecimal.ZERO));
    assertThat(state.getMaximum(), is(BigDecimal.valueOf(100.0)));
    assertThat(state.getStep(), is(BigDecimal.valueOf(10.0)));
    assertThat(state.getPattern(), is(equalTo("%d Peek")));
    assertThat(state.isReadOnly(), is(true));
    assertThat(state.getOptions().size(), is(2));
    assertThat(state.getOptions().get(0).getValue(), is(equalTo("SOUND")));
    assertThat(state.getOptions().get(0).getLabel(), is(equalTo("My great sound.")));
    thingType = thingTypes.stream().filter(it -> it.toString().equals("hue:lamp-with-group")).findFirst().get();
    assertThat(thingType.getProperties().size(), is(0));
    assertThat(thingType.getCategory(), is(nullValue()));
    assertThat(thingType.isListed(), is(true));
    assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("brightness", "alarm"));
    // uninstall test bundle
    bundle.uninstall();
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) IsIterableContainingInAnyOrder.containsInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder) Collection(java.util.Collection) SyntheticBundleInstaller(org.eclipse.smarthome.test.SyntheticBundleInstaller) Set(java.util.Set) Test(org.junit.Test) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) List(java.util.List) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ChannelTypeRegistry(org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry) ThingTypeProvider(org.eclipse.smarthome.core.thing.binding.ThingTypeProvider) After(org.junit.After) BridgeType(org.eclipse.smarthome.core.thing.type.BridgeType) StateDescription(org.eclipse.smarthome.core.types.StateDescription) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) Before(org.junit.Before) Bundle(org.osgi.framework.Bundle) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) BridgeType(org.eclipse.smarthome.core.thing.type.BridgeType) StateDescription(org.eclipse.smarthome.core.types.StateDescription) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 7 with ChannelType

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

the class ChannelTypesI18nTest method channelTypesShouldTranslateCorrectly.

@Test
public void channelTypesShouldTranslateCorrectly() throws Exception {
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));
    Collection<ChannelType> channelTypes = channelTypeProvider.getChannelTypes(null);
    ChannelType channelType1 = channelTypes.stream().filter(c -> c.getUID().toString().equals("somebinding:channel-with-i18n")).findFirst().get();
    assertThat(channelType1, is(not(nullValue())));
    assertThat(channelType1.getLabel(), is(equalTo("Channel Label")));
    assertThat(channelType1.getDescription(), is(equalTo("Channel Description")));
    Collection<ChannelGroupType> channelGroupTypes = channelGroupTypeProvider.getChannelGroupTypes(null);
    ChannelGroupType channelGroupType = channelGroupTypes.stream().filter(c -> c.getUID().toString().equals("somebinding:channelgroup-with-i18n")).findFirst().get();
    assertThat(channelGroupType, is(not(nullValue())));
    assertThat(channelGroupType.getLabel(), is(equalTo("Channel Group Label")));
    assertThat(channelGroupType.getDescription(), is(equalTo("Channel Group Description")));
}
Also used : Bundle(org.osgi.framework.Bundle) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 8 with ChannelType

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

the class ChannelTypesTest method ChannelTypesShouldBeLoaded.

@Test
public void ChannelTypesShouldBeLoaded() throws Exception {
    int initialNumberOfChannelTypes = channelTypeProvider.getChannelTypes(null).size();
    int initialNumberOfChannelGroupTypes = channelGroupTypeProvider.getChannelGroupTypes(null).size();
    // install test bundle
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));
    Collection<ChannelType> channelTypes = channelTypeProvider.getChannelTypes(null);
    assertThat(channelTypes.size(), is(initialNumberOfChannelTypes + 2));
    ChannelType channelType1 = channelTypes.stream().filter(it -> it.getUID().toString().equals("somebinding:channel1")).findFirst().get();
    assertThat(channelType1, is(not(nullValue())));
    ChannelType channelType2 = channelTypes.stream().filter(it -> it.getUID().toString().equals("somebinding:channel-without-reference")).findFirst().get();
    assertThat(channelType2, is(not(nullValue())));
    Collection<ChannelGroupType> channelGroupTypes = channelGroupTypeProvider.getChannelGroupTypes(null);
    assertThat(channelGroupTypes.size(), is(initialNumberOfChannelGroupTypes + 1));
    ChannelGroupType channelGroupType = channelGroupTypes.stream().filter(it -> it.getUID().toString().equals("somebinding:channelgroup")).findFirst().get();
    assertThat(channelGroupType, is(not(nullValue())));
    assertThat(channelGroupType.getCategory(), is("Temperature"));
    SyntheticBundleInstaller.uninstall(bundleContext, TEST_BUNDLE_NAME);
    assertThat(channelTypeProvider.getChannelTypes(null).size(), is(initialNumberOfChannelTypes));
    assertThat(channelGroupTypeProvider.getChannelGroupTypes(null).size(), is(initialNumberOfChannelGroupTypes));
}
Also used : Bundle(org.osgi.framework.Bundle) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 9 with ChannelType

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

the class Example method test.

@SuppressWarnings("unchecked")
@Test
public void test() throws Exception {
    File file = new File("./example/example.xml");
    URL channelsURL = file.toURI().toURL();
    ThingDescriptionReader reader = new ThingDescriptionReader();
    ThingDescriptionList thingList = (ThingDescriptionList) reader.readFromXML(channelsURL);
    thingList.stream().forEach(it -> {
        if (it instanceof ChannelTypeXmlResult) {
            ChannelType channelType = ((ChannelTypeXmlResult) it).toChannelType();
        }
    });
}
Also used : ThingDescriptionReader(org.eclipse.smarthome.core.thing.xml.internal.ThingDescriptionReader) ChannelTypeXmlResult(org.eclipse.smarthome.core.thing.xml.internal.ChannelTypeXmlResult) ThingDescriptionList(org.eclipse.smarthome.core.thing.xml.internal.ThingDescriptionList) File(java.io.File) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) URL(java.net.URL) Test(org.junit.Test)

Example 10 with ChannelType

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

the class NtpOSGiTest method setUp.

@Before
public void setUp() {
    VolatileStorageService volatileStorageService = new VolatileStorageService();
    registerService(volatileStorageService);
    managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
    assertNotNull(managedThingProvider);
    thingRegistry = getService(ThingRegistry.class);
    assertNotNull(thingRegistry);
    itemRegistry = getService(ItemRegistry.class);
    assertNotNull(itemRegistry);
    channelTypeUID = new ChannelTypeUID(NtpBindingConstants.BINDING_ID + ":channelType");
    channelTypeProvider = mock(ChannelTypeProvider.class);
    when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), any(Locale.class))).thenReturn(new ChannelType(channelTypeUID, false, "Switch", ChannelKind.STATE, "label", null, null, null, null, null, null));
    registerService(channelTypeProvider);
}
Also used : Locale(java.util.Locale) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ThingProvider(org.eclipse.smarthome.core.thing.ThingProvider) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) Before(org.junit.Before)

Aggregations

ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)23 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)9 StateDescription (org.eclipse.smarthome.core.types.StateDescription)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 Bundle (org.osgi.framework.Bundle)5 ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)4 Locale (java.util.Locale)3 Channel (org.eclipse.smarthome.core.thing.Channel)3 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)3 ChannelGroupType (org.eclipse.smarthome.core.thing.type.ChannelGroupType)3 ChannelTypeProvider (org.eclipse.smarthome.core.thing.type.ChannelTypeProvider)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 URI (java.net.URI)2 Collection (java.util.Collection)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2