Search in sources :

Example 11 with ChannelDefinition

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()));
}
Also used : Bundle(org.osgi.framework.Bundle) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 12 with ChannelDefinition

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()));
}
Also used : Bundle(org.osgi.framework.Bundle) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 13 with ChannelDefinition

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;
}
Also used : ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) Channel(org.eclipse.smarthome.core.thing.Channel) ArrayList(java.util.ArrayList) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupDefinition(org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition)

Example 14 with ChannelDefinition

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;
}
Also used : ChannelDefinitionDTO(org.eclipse.smarthome.core.thing.dto.ChannelDefinitionDTO) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType)

Aggregations

ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)14 ThingType (org.eclipse.smarthome.core.thing.type.ThingType)7 ArrayList (java.util.ArrayList)6 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)6 Test (org.junit.Test)6 Bundle (org.osgi.framework.Bundle)6 ChannelGroupType (org.eclipse.smarthome.core.thing.type.ChannelGroupType)5 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)4 Collection (java.util.Collection)3 ThingTypeProvider (org.eclipse.smarthome.core.thing.binding.ThingTypeProvider)3 ChannelGroupDefinition (org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition)3 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)3 Before (org.junit.Before)3 List (java.util.List)2 Channel (org.eclipse.smarthome.core.thing.Channel)2 ChannelDefinitionDTO (org.eclipse.smarthome.core.thing.dto.ChannelDefinitionDTO)2 BridgeType (org.eclipse.smarthome.core.thing.type.BridgeType)2 ChannelGroupTypeUID (org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID)2 ChannelTypeRegistry (org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry)2 ThingTypeBuilder (org.eclipse.smarthome.core.thing.type.ThingTypeBuilder)2