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;
}
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();
}
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;
}
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."));
}
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")));
}
Aggregations