use of org.openhab.core.thing.type.ChannelDefinition in project openhab-core by openhab.
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();
withChannelGroupTypeRegistry(channelGroupTypeRegistry -> {
for (ChannelGroupDefinition channelGroupDefinition : channelGroupDefinitions) {
ChannelGroupType channelGroupType = null;
if (channelGroupTypeRegistry != null) {
channelGroupType = channelGroupTypeRegistry.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;
}
use of org.openhab.core.thing.type.ChannelDefinition in project openhab-core by openhab.
the class ChannelGroupTypeI18nLocalizationService method createLocalizedChannelGroupType.
public ChannelGroupType createLocalizedChannelGroupType(Bundle bundle, ChannelGroupType channelGroupType, @Nullable Locale locale) {
ChannelGroupTypeUID channelGroupTypeUID = channelGroupType.getUID();
String defaultLabel = channelGroupType.getLabel();
String label = thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupTypeUID, defaultLabel, locale);
String description = thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupTypeUID, channelGroupType.getDescription(), locale);
List<ChannelDefinition> localizedChannelDefinitions = channelI18nUtil.createLocalizedChannelDefinitions(bundle, channelGroupType.getChannelDefinitions(), channelDefinition -> thingTypeI18nUtil.getChannelLabel(bundle, channelGroupTypeUID, channelDefinition, channelDefinition.getLabel(), locale), channelDefinition -> thingTypeI18nUtil.getChannelDescription(bundle, channelGroupTypeUID, channelDefinition, channelDefinition.getDescription(), locale), locale);
ChannelGroupTypeBuilder builder = ChannelGroupTypeBuilder.instance(channelGroupTypeUID, label == null ? defaultLabel : label).withChannelDefinitions(localizedChannelDefinitions);
if (description != null) {
builder.withDescription(description);
}
String category = channelGroupType.getCategory();
if (category != null) {
builder.withCategory(category);
}
return builder.build();
}
use of org.openhab.core.thing.type.ChannelDefinition in project openhab-core by openhab.
the class SystemChannelsInChannelGroupsTest method thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDefinitions.
@Test
public void thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDefinitions() throws Exception {
try (final AutoCloseable unused = loadedTestBundle()) {
List<ThingType> thingTypes = thingTypeProvider.getThingTypes(null).stream().filter(it -> "wireless-router".equals(it.getUID().getId())).collect(Collectors.toList());
assertThat(thingTypes.size(), is(1));
List<ChannelGroupType> channelGroupTypes = channelGroupTypeRegistry.getChannelGroupTypes();
ChannelGroupType channelGroup = channelGroupTypes.stream().filter(it -> it.getUID().equals(new ChannelGroupTypeUID("SystemChannelsInChannelGroups:channelGroup"))).findFirst().get();
assertThat(channelGroup, is(notNullValue()));
List<ChannelDefinition> channelDefs = channelGroup.getChannelDefinitions();
List<ChannelDefinition> myChannel = channelDefs.stream().filter(it -> "test".equals(it.getId()) && "system:my-channel".equals(it.getChannelTypeUID().getAsString())).collect(Collectors.toList());
List<ChannelDefinition> sigStr = channelDefs.stream().filter(it -> "sigstr".equals(it.getId()) && "system:signal-strength".equals(it.getChannelTypeUID().getAsString())).collect(Collectors.toList());
List<ChannelDefinition> lowBat = channelDefs.stream().filter(it -> "lowbat".equals(it.getId()) && "system:low-battery".equals(it.getChannelTypeUID().getAsString())).collect(Collectors.toList());
assertThat(myChannel.size(), is(1));
assertThat(sigStr.size(), is(1));
assertThat(lowBat.size(), is(1));
}
}
use of org.openhab.core.thing.type.ChannelDefinition in project openhab-core by openhab.
the class SystemWideChannelTypesTest method systemChannelsShouldTranslateProperly.
@Test
public void systemChannelsShouldTranslateProperly() throws Exception {
try (final AutoCloseable unused = loadedSystemChannelsBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
ThingType wirelessRouterType = thingTypes.stream().filter(it -> "SystemChannels:wireless-router".equals(it.getUID().getAsString())).findFirst().get();
assertNotNull(wirelessRouterType);
List<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
assertEquals(3, channelDefs.size());
ChannelDefinition myChannel = channelDefs.stream().filter(it -> "test".equals(it.getId()) && "system:my-channel".equals(it.getChannelTypeUID().getAsString())).findFirst().get();
assertNotNull(myChannel);
ChannelDefinition sigStr = channelDefs.stream().filter(it -> "sigstr".equals(it.getId()) && "system:signal-strength".equals(it.getChannelTypeUID().getAsString())).findFirst().get();
assertNotNull(sigStr);
ChannelDefinition lowBat = channelDefs.stream().filter(it -> "lowbat".equals(it.getId()) && "system:low-battery".equals(it.getChannelTypeUID().getAsString())).findFirst().get();
assertNotNull(lowBat);
ChannelType lowBatType = systemChannelTypeProvider.getChannelType(lowBat.getChannelTypeUID(), Locale.GERMAN);
ChannelType myChannelChannelType = channelTypeRegistry.getChannelType(myChannel.getChannelTypeUID(), Locale.GERMAN);
assertNotNull(myChannelChannelType);
assertEquals("Mein String My Channel", myChannelChannelType.getLabel());
assertEquals("Wetterinformation mit My Channel Type Beschreibung", myChannelChannelType.getDescription());
assertEquals("Mein String My Channel", myChannel.getLabel());
assertEquals("Wetterinformation mit My Channel Type Beschreibung", myChannel.getDescription());
assertEquals("Meine spezial Signalstärke", sigStr.getLabel());
assertEquals("Meine spezial Beschreibung für Signalstärke", sigStr.getDescription());
assertEquals("Niedriger Batteriestatus", lowBatType.getLabel());
assertNull(lowBatType.getDescription());
}
}
use of org.openhab.core.thing.type.ChannelDefinition in project openhab-core by openhab.
the class ThingTypeI18nTest method channelsInGroupTypeShouldBeLocalized.
@Test
public void channelsInGroupTypeShouldBeLocalized() throws Exception {
try (final AutoCloseable unused = loadedTestBundle()) {
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
ThingType weatherGroupType = thingTypes.stream().filter(it -> "acmeweather:weather-with-group".equals(it.toString())).findFirst().get();
assertNotNull(weatherGroupType);
assertEquals(2, weatherGroupType.getChannelGroupDefinitions().size());
ChannelGroupDefinition forecastTodayChannelGroupDefinition = weatherGroupType.getChannelGroupDefinitions().stream().filter(it -> "forecastToday".equals(it.getId())).findFirst().get();
assertNotNull(forecastTodayChannelGroupDefinition);
ChannelGroupType forecastTodayChannelGroupType = channelGroupTypeRegistry.getChannelGroupType(forecastTodayChannelGroupDefinition.getTypeUID(), Locale.GERMAN);
assertNotNull(forecastTodayChannelGroupType);
assertEquals(3, forecastTodayChannelGroupType.getChannelDefinitions().size());
ChannelDefinition temperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions().stream().filter(it -> "temperature".equals(it.getId())).findFirst().get();
assertNotNull(temperatureChannelDefinition);
assertEquals("Temperatur", temperatureChannelDefinition.getLabel());
assertEquals("Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).", temperatureChannelDefinition.getDescription());
ChannelDefinition minTemperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions().stream().filter(it -> "minTemperature".equals(it.getId())).findFirst().get();
assertNotNull(minTemperatureChannelDefinition);
assertEquals("Min. Temperatur", minTemperatureChannelDefinition.getLabel());
assertEquals("Minimale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).", minTemperatureChannelDefinition.getDescription());
ChannelDefinition maxTemperatureChannelDefinition = forecastTodayChannelGroupType.getChannelDefinitions().stream().filter(it -> "maxTemperature".equals(it.getId())).findFirst().get();
assertNotNull(maxTemperatureChannelDefinition);
assertEquals("Max. Temperatur", maxTemperatureChannelDefinition.getLabel());
assertEquals("Maximale vorhergesagte Temperatur in Grad Celsius (Metrisch) oder Fahrenheit (Imperial).", maxTemperatureChannelDefinition.getDescription());
}
}
Aggregations