Search in sources :

Example 1 with ChannelDefinition

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

the class ThingTypeResource method convertToChannelGroupDefinitionDTOs.

private List<ChannelGroupDefinitionDTO> convertToChannelGroupDefinitionDTOs(List<ChannelGroupDefinition> channelGroupDefinitions, Locale locale) {
    List<ChannelGroupDefinitionDTO> channelGroupDefinitionDTOs = new ArrayList<>();
    for (ChannelGroupDefinition channelGroupDefinition : channelGroupDefinitions) {
        String id = channelGroupDefinition.getId();
        ChannelGroupType channelGroupType = channelTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID(), locale);
        // Default to the channelGroupDefinition label to override the
        // channelGroupType
        String label = channelGroupDefinition.getLabel();
        if (label == null) {
            label = channelGroupType.getLabel();
        }
        // Default to the channelGroupDefinition description to override the
        // channelGroupType
        String description = channelGroupDefinition.getDescription();
        if (description == null) {
            description = channelGroupType.getDescription();
        }
        List<ChannelDefinition> channelDefinitions = channelGroupType.getChannelDefinitions();
        List<ChannelDefinitionDTO> channelDefinitionDTOs = convertToChannelDefinitionDTOs(channelDefinitions, locale);
        channelGroupDefinitionDTOs.add(new ChannelGroupDefinitionDTO(id, label, description, channelDefinitionDTOs));
    }
    return channelGroupDefinitionDTOs;
}
Also used : ChannelDefinitionDTO(org.eclipse.smarthome.core.thing.dto.ChannelDefinitionDTO) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelGroupDefinitionDTO(org.eclipse.smarthome.core.thing.dto.ChannelGroupDefinitionDTO) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupDefinition(org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition)

Example 2 with ChannelDefinition

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

the class ThingTypeI18nLocalizationService method createLocalizedThingType.

public ThingType createLocalizedThingType(Bundle bundle, ThingType thingType, Locale locale) {
    final String label = this.thingTypeI18nUtil.getLabel(bundle, thingType.getUID(), thingType.getLabel(), locale);
    final String description = this.thingTypeI18nUtil.getDescription(bundle, thingType.getUID(), thingType.getDescription(), locale);
    final List<ChannelDefinition> localizedChannelDefinitions = new ArrayList<>(thingType.getChannelDefinitions().size());
    for (final ChannelDefinition channelDefinition : thingType.getChannelDefinitions()) {
        String channelLabel = this.thingTypeI18nUtil.getChannelLabel(bundle, thingType.getUID(), channelDefinition, channelDefinition.getLabel(), locale);
        String channelDescription = this.thingTypeI18nUtil.getChannelDescription(bundle, thingType.getUID(), channelDefinition, channelDefinition.getDescription(), locale);
        if (channelLabel == null || channelDescription == null) {
            ChannelType channelType = channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID(), locale);
            if (channelType != null) {
                if (channelLabel == null) {
                    channelLabel = this.thingTypeI18nUtil.getChannelLabel(bundle, channelType.getUID(), channelType.getLabel(), locale);
                }
                if (channelDescription == null) {
                    channelDescription = this.thingTypeI18nUtil.getChannelDescription(bundle, channelType.getUID(), channelType.getDescription(), locale);
                }
            }
        }
        localizedChannelDefinitions.add(new ChannelDefinition(channelDefinition.getId(), channelDefinition.getChannelTypeUID(), channelDefinition.getProperties(), channelLabel, channelDescription));
    }
    final List<ChannelGroupDefinition> localizedChannelGroupDefinitions = new ArrayList<>(thingType.getChannelGroupDefinitions().size());
    for (final ChannelGroupDefinition channelGroupDefinition : thingType.getChannelGroupDefinitions()) {
        String channelGroupLabel = this.thingTypeI18nUtil.getChannelGroupLabel(bundle, thingType.getUID(), channelGroupDefinition, channelGroupDefinition.getLabel(), locale);
        String channelGroupDescription = this.thingTypeI18nUtil.getChannelGroupDescription(bundle, thingType.getUID(), channelGroupDefinition, channelGroupDefinition.getDescription(), locale);
        if (channelGroupLabel == null || channelGroupDescription == null) {
            ChannelGroupType channelGroupType = channelTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID(), locale);
            if (channelGroupType != null) {
                if (channelGroupLabel == null) {
                    channelGroupLabel = this.thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupType.getUID(), channelGroupType.getLabel(), locale);
                }
                if (channelGroupDescription == null) {
                    channelGroupDescription = this.thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupType.getUID(), channelGroupType.getDescription(), locale);
                }
            }
        }
        localizedChannelGroupDefinitions.add(new ChannelGroupDefinition(channelGroupDefinition.getId(), channelGroupDefinition.getTypeUID(), channelGroupLabel, channelGroupDescription));
    }
    ThingTypeBuilder builder = ThingTypeBuilder.instance(thingType).withLabel(label).withDescription(description).withChannelDefinitions(localizedChannelDefinitions).withChannelGroupDefinitions(localizedChannelGroupDefinitions);
    if (thingType instanceof BridgeType) {
        return builder.buildBridge();
    }
    return builder.build();
}
Also used : ThingTypeBuilder(org.eclipse.smarthome.core.thing.type.ThingTypeBuilder) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ChannelGroupDefinition(org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition) BridgeType(org.eclipse.smarthome.core.thing.type.BridgeType)

Example 3 with ChannelDefinition

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

the class ThingTypeI18nTest method channelsShouldBeLocalized.

@Test
public void channelsShouldBeLocalized() 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(Locale.GERMAN);
    assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 2));
    ThingType weatherType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather")).findFirst().get();
    assertThat(weatherType, is(notNullValue()));
    assertThat(weatherType.getChannelDefinitions().size(), is(2));
    ChannelDefinition temperatureChannelDefinition = weatherType.getChannelDefinitions().stream().filter(it -> it.getId().equals("temperature")).findFirst().get();
    assertThat(temperatureChannelDefinition, is(notNullValue()));
    assertThat(temperatureChannelDefinition.getLabel(), is("Temperatur"));
    assertThat(temperatureChannelDefinition.getDescription(), is("Aktuelle Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
    ChannelDefinition minTemperatureChannelDefinition = weatherType.getChannelDefinitions().stream().filter(it -> it.getId().equals("minTemperature")).findFirst().get();
    assertThat(minTemperatureChannelDefinition, is(notNullValue()));
    assertThat(minTemperatureChannelDefinition.getLabel(), is("Min. Temperatur"));
    assertThat(minTemperatureChannelDefinition.getDescription(), is("Minimale Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial)."));
}
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)

Example 4 with ChannelDefinition

use of org.eclipse.smarthome.core.thing.type.ChannelDefinition 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 5 with ChannelDefinition

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

the class ChannelTypesI18nTest method channelDefinitionsShouldBeTranslatedCorrectly.

@Test
public void channelDefinitionsShouldBeTranslatedCorrectly() throws Exception {
    Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
    assertThat(bundle, is(notNullValue()));
    ThingType thingType = thingTypeProvider.getThingTypes(null).stream().filter(it -> it.getUID().toString().equals("somebinding:something")).findFirst().get();
    assertThat(thingType, is(notNullValue()));
    assertThat(thingType.getChannelDefinitions().size(), is(2));
    ChannelDefinition channelDefinition1 = thingType.getChannelDefinitions().stream().filter(it -> it.getId().equals("channelPlain")).findFirst().get();
    assertThat(channelDefinition1.getLabel(), is(equalTo("Channel Plain Label")));
    assertThat(channelDefinition1.getDescription(), is(equalTo("Channel Plain Description")));
    ChannelDefinition channelDefinition2 = thingType.getChannelDefinitions().stream().filter(it -> it.getId().equals("channelInplace")).findFirst().get();
    assertThat(channelDefinition2.getLabel(), is(equalTo("Channel Inplace Label")));
    assertThat(channelDefinition2.getDescription(), is(equalTo("Channel Inplace Description")));
}
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

ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)14 ThingType (org.eclipse.smarthome.core.thing.type.ThingType)7 ArrayList (java.util.ArrayList)6 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)6 Test (org.junit.Test)6 Bundle (org.osgi.framework.Bundle)6 ChannelGroupType (org.eclipse.smarthome.core.thing.type.ChannelGroupType)5 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)4 Collection (java.util.Collection)3 ThingTypeProvider (org.eclipse.smarthome.core.thing.binding.ThingTypeProvider)3 ChannelGroupDefinition (org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition)3 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)3 Before (org.junit.Before)3 List (java.util.List)2 Channel (org.eclipse.smarthome.core.thing.Channel)2 ChannelDefinitionDTO (org.eclipse.smarthome.core.thing.dto.ChannelDefinitionDTO)2 BridgeType (org.eclipse.smarthome.core.thing.type.BridgeType)2 ChannelGroupTypeUID (org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID)2 ChannelTypeRegistry (org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry)2 ThingTypeBuilder (org.eclipse.smarthome.core.thing.type.ThingTypeBuilder)2