use of org.eclipse.smarthome.core.thing.type.ChannelDefinition in project smarthome by eclipse.
the class SystemWideChannelTypesTest method systemChannelsShouldTranslateProperly.
@Test
public void systemChannelsShouldTranslateProperly() throws Exception {
int initialNumberOfThingTypes = thingTypeProvider.getThingTypes(null).size();
// install test bundle
Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
assertThat(sysBundle, is(notNullValue()));
Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(Locale.GERMAN);
assertThat(thingTypes.size(), is(initialNumberOfThingTypes + 1));
ThingType wirelessRouterType = thingTypes.stream().filter(it -> it.getUID().getAsString().equals("SystemChannels:wireless-router")).findFirst().get();
assertThat(wirelessRouterType, is(notNullValue()));
List<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
assertThat(channelDefs.size(), is(3));
ChannelDefinition myChannel = channelDefs.stream().filter(it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel")).findFirst().get();
assertThat(myChannel, is(notNullValue()));
ChannelDefinition sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr") && it.getChannelTypeUID().getAsString().equals("system:signal-strength")).findFirst().get();
assertThat(sigStr, is(notNullValue()));
ChannelDefinition lowBat = channelDefs.stream().filter(it -> it.getId().equals("lowbat") && it.getChannelTypeUID().getAsString().equals("system:low-battery")).findFirst().get();
assertThat(lowBat, is(notNullValue()));
assertThat(channelTypeRegistry.getChannelType(myChannel.getChannelTypeUID(), Locale.GERMAN).getLabel(), is("Mein String My Channel"));
assertThat(channelTypeRegistry.getChannelType(myChannel.getChannelTypeUID(), Locale.GERMAN).getDescription(), is("Wetterinformation mit My Channel Type Beschreibung"));
assertThat(myChannel.getLabel(), is("Mein String My Channel"));
assertThat(myChannel.getDescription(), is("Wetterinformation mit My Channel Type Beschreibung"));
assertThat(channelTypeRegistry.getChannelType(sigStr.getChannelTypeUID(), Locale.GERMAN).getLabel(), is("Signalstärke"));
assertThat(sigStr.getLabel(), is("Meine spezial Signalstärke"));
assertThat(sigStr.getDescription(), is("Meine spezial Beschreibung für Signalstärke"));
assertThat(channelTypeRegistry.getChannelType(lowBat.getChannelTypeUID(), Locale.GERMAN).getLabel(), is("Niedriger Batteriestatus"));
assertThat(lowBat.getLabel(), is("Niedriger Batteriestatus"));
assertThat(lowBat.getDescription(), is(nullValue()));
}
use of org.eclipse.smarthome.core.thing.type.ChannelDefinition in project smarthome by eclipse.
the class SystemWideChannelTypesTest method thingTyoesShouldHaveProperChannelDefinitions.
@Test
public void thingTyoesShouldHaveProperChannelDefinitions() throws Exception {
// install test bundle
Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_BUNDLE_NAME);
assertThat(sysBundle, is(notNullValue()));
ThingType wirelessRouterType = thingTypeProvider.getThingTypes(null).stream().filter(it -> it.getUID().getAsString().equals("SystemChannels:wireless-router")).findFirst().get();
assertThat(wirelessRouterType, is(notNullValue()));
Collection<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
assertThat(channelDefs.size(), is(3));
ChannelDefinition myChannel = channelDefs.stream().filter(it -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel")).findFirst().get();
assertThat(myChannel, is(notNullValue()));
ChannelDefinition sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr") && it.getChannelTypeUID().getAsString().equals("system:signal-strength")).findFirst().get();
assertThat(sigStr, is(notNullValue()));
ChannelDefinition lowBat = channelDefs.stream().filter(it -> it.getId().equals("lowbat") && it.getChannelTypeUID().getAsString().equals("system:low-battery")).findFirst().get();
assertThat(lowBat, is(notNullValue()));
}
use of org.eclipse.smarthome.core.thing.type.ChannelDefinition 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;
}
use of org.eclipse.smarthome.core.thing.type.ChannelDefinition in project smarthome by eclipse.
the class ThingTypeResource method convertToChannelDefinitionDTOs.
private List<ChannelDefinitionDTO> convertToChannelDefinitionDTOs(List<ChannelDefinition> channelDefinitions, Locale locale) {
List<ChannelDefinitionDTO> channelDefinitionDTOs = new ArrayList<>();
for (ChannelDefinition channelDefinition : channelDefinitions) {
ChannelType channelType = channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID(), locale);
if (channelType == null) {
logger.warn("Cannot find channel type: {}", channelDefinition.getChannelTypeUID());
return null;
}
// Default to the channelDefinition label to override the
// channelType
String label = channelDefinition.getLabel();
if (label == null) {
label = channelType.getLabel();
}
// Default to the channelDefinition description to override the
// channelType
String description = channelDefinition.getDescription();
if (description == null) {
description = channelType.getDescription();
}
ChannelDefinitionDTO channelDefinitionDTO = new ChannelDefinitionDTO(channelDefinition.getId(), channelDefinition.getChannelTypeUID().toString(), label, description, channelType.getTags(), channelType.getCategory(), channelType.getState(), channelType.isAdvanced(), channelDefinition.getProperties());
channelDefinitionDTOs.add(channelDefinitionDTO);
}
return channelDefinitionDTOs;
}
Aggregations