use of org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition 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.ChannelGroupDefinition 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.ChannelGroupDefinition in project smarthome by eclipse.
the class ThingTypeI18nTest method channelGroupsShouldBeLocalized.
@Test
public void channelGroupsShouldBeLocalized() 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()));
assertThat(weatherGroupType.getChannelGroupDefinitions().size(), is(2));
ChannelGroupDefinition forecastTodayChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions().stream().filter(it -> it.getId().equals("forecastToday")).findFirst().get();
assertThat(forecastTodayChannelGroupDefinition, is(notNullValue()));
assertThat(forecastTodayChannelGroupDefinition.getLabel(), is("Wettervorhersage heute"));
assertThat(forecastTodayChannelGroupDefinition.getDescription(), is("Wettervorhersage für den heutigen Tag."));
ChannelGroupDefinition forecastTomorrowChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions().stream().filter(it -> it.getId().equals("forecastTomorrow")).findFirst().get();
assertThat(forecastTomorrowChannelGroupDefinition, is(notNullValue()));
assertThat(forecastTomorrowChannelGroupDefinition.getLabel(), is("Wettervorhersage morgen"));
assertThat(forecastTomorrowChannelGroupDefinition.getDescription(), is("Wettervorhersage für den morgigen Tag."));
}
use of org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition in project smarthome by eclipse.
the class ThingTypeXmlResult method toChannelGroupDefinitions.
protected List<ChannelGroupDefinition> toChannelGroupDefinitions(List<ChannelXmlResult> channelGroupTypeReferences) throws ConversionException {
List<ChannelGroupDefinition> channelGroupTypeDefinitions = null;
if ((channelGroupTypeReferences != null) && (channelGroupTypeReferences.size() > 0)) {
channelGroupTypeDefinitions = new ArrayList<>(channelGroupTypeReferences.size());
for (ChannelXmlResult channelGroupTypeReference : channelGroupTypeReferences) {
String id = channelGroupTypeReference.getId();
String typeId = channelGroupTypeReference.getTypeId();
String typeUID = String.format("%s:%s", this.thingTypeUID.getBindingId(), typeId);
ChannelGroupDefinition channelGroupDefinition = new ChannelGroupDefinition(id, new ChannelGroupTypeUID(typeUID), channelGroupTypeReference.getLabel(), channelGroupTypeReference.getDescription());
channelGroupTypeDefinitions.add(channelGroupDefinition);
}
}
return channelGroupTypeDefinitions;
}
use of org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition in project smarthome by eclipse.
the class ThingFactoryHelper method createChannels.
/**
* Create {@link Channel} instances for the given Thing.
*
* @param thingType the type of the Thing (must not be null)
* @param thingUID the Thing's UID (must not be null)
* @param configDescriptionRegistry {@link ConfigDescriptionRegistry} that will be used to initialize the
* {@link Channel}s with their corresponding default values, if given.
* @return a list of {@link Channel}s
*/
public static List<Channel> createChannels(ThingType thingType, ThingUID thingUID, ConfigDescriptionRegistry configDescriptionRegistry) {
List<Channel> channels = new ArrayList<>();
List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
for (ChannelDefinition channelDefinition : channelDefinitions) {
Channel channel = createChannel(channelDefinition, thingUID, null, configDescriptionRegistry);
if (channel != null) {
channels.add(channel);
}
}
List<ChannelGroupDefinition> channelGroupDefinitions = thingType.getChannelGroupDefinitions();
withChannelTypeRegistry(channelTypeRegistry -> {
for (ChannelGroupDefinition channelGroupDefinition : channelGroupDefinitions) {
ChannelGroupType channelGroupType = null;
if (channelTypeRegistry != null) {
channelGroupType = channelTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID());
}
if (channelGroupType != null) {
List<ChannelDefinition> channelGroupChannelDefinitions = channelGroupType.getChannelDefinitions();
for (ChannelDefinition channelDefinition : channelGroupChannelDefinitions) {
Channel channel = createChannel(channelDefinition, thingUID, channelGroupDefinition.getId(), configDescriptionRegistry);
if (channel != null) {
channels.add(channel);
}
}
} else {
logger.warn("Could not create channels for channel group '{}' for thing type '{}', because channel group type '{}' could not be found.", channelGroupDefinition.getId(), thingUID, channelGroupDefinition.getTypeUID());
}
}
return null;
});
return channels;
}
Aggregations