Search in sources :

Example 1 with ChannelGroupType

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

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

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

the class XmlChannelGroupTypeProvider method localize.

@Override
protected ChannelGroupType localize(Bundle bundle, ChannelGroupType channelGroupType, Locale locale) {
    if (this.thingTypeI18nUtil == null) {
        return null;
    }
    ChannelGroupTypeUID channelGroupTypeUID = channelGroupType.getUID();
    String label = this.thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupTypeUID, channelGroupType.getLabel(), locale);
    String description = this.thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupTypeUID, channelGroupType.getDescription(), locale);
    ChannelGroupType localizedChannelGroupType = new ChannelGroupType(channelGroupTypeUID, channelGroupType.isAdvanced(), label, description, channelGroupType.getCategory(), channelGroupType.getChannelDefinitions());
    return localizedChannelGroupType;
}
Also used : ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType)

Example 4 with ChannelGroupType

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

the class ThingTypeI18nTest method channelGroupTypeShouldBeLocalized.

@Test
public void channelGroupTypeShouldBeLocalized() 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 weatherGroupType = thingTypes.stream().filter(it -> it.toString().equals("yahooweather:weather-with-group")).findFirst().get();
    assertThat(weatherGroupType, is(notNullValue()));
    ChannelGroupType channelGroupType = channelTypeRegistry.getChannelGroupType(weatherGroupType.getChannelGroupDefinitions().get(0).getTypeUID(), Locale.GERMAN);
    assertThat(channelGroupType, is(notNullValue()));
    assertThat(channelGroupType.getLabel(), is("Wetterinformation mit Gruppe"));
    assertThat(channelGroupType.getDescription(), is("Wetterinformation mit Gruppe Beschreibung."));
}
Also used : Bundle(org.osgi.framework.Bundle) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 5 with ChannelGroupType

use of org.eclipse.smarthome.core.thing.type.ChannelGroupType 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)

Aggregations

ChannelGroupType (org.eclipse.smarthome.core.thing.type.ChannelGroupType)9 ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)5 ArrayList (java.util.ArrayList)4 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 Test (org.junit.Test)4 Bundle (org.osgi.framework.Bundle)4 ChannelGroupDefinition (org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition)3 ChannelGroupTypeUID (org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID)3 Collection (java.util.Collection)2 Channel (org.eclipse.smarthome.core.thing.Channel)2 ThingType (org.eclipse.smarthome.core.thing.type.ThingType)2 Before (org.junit.Before)2 List (java.util.List)1 Locale (java.util.Locale)1 Collectors (java.util.stream.Collectors)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Item (org.eclipse.smarthome.core.items.Item)1 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)1 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)1