Search in sources :

Example 21 with ChannelDefinition

use of org.openhab.core.thing.type.ChannelDefinition in project openhab-core by openhab.

the class ThingTypesTest method thingTypesShouldLoad.

@Test
public void thingTypesShouldLoad() throws Exception {
    try (final AutoCloseable unused = loadedTestBundle()) {
        Collection<ThingType> thingTypes = thingTypeProvider.getThingTypes(null);
        // HUE Bridge
        BridgeType bridgeType = (BridgeType) thingTypes.stream().filter(it -> "hue:bridge".equals(it.toString())).findFirst().get();
        assertThat(bridgeType, is(notNullValue()));
        assertThat(bridgeType.getCategory(), is("NetworkAppliance"));
        assertThat(bridgeType.isListed(), is(false));
        assertThat(bridgeType.getLabel(), is("HUE Bridge"));
        assertThat(bridgeType.getDescription(), is("The hue Bridge represents the Philips hue bridge."));
        assertThat(bridgeType.getProperties().size(), is(1));
        assertThat(bridgeType.getProperties().get("vendor"), is("Philips"));
        assertThat(bridgeType.getRepresentationProperty(), is("serialNumber"));
        // HUE Lamp
        ThingType thingType = thingTypes.stream().filter(it -> "hue:lamp".equals(it.toString())).findFirst().get();
        assertThat(thingType, is(notNullValue()));
        assertThat(thingType.getCategory(), is("Lightbulb"));
        assertThat(thingType.isListed(), is(false));
        assertThat(thingType.getLabel(), is("HUE Lamp"));
        assertThat(thingType.getDescription(), is("My own great HUE Lamp."));
        assertThat(thingType.getSupportedBridgeTypeUIDs().size(), is(1));
        assertThat(thingType.getSupportedBridgeTypeUIDs().get(0), is("hue:bridge"));
        assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("alarm", "brightness"));
        assertThat(thingType.getProperties().size(), is(2));
        assertThat(thingType.getProperties().get("key1"), is("value1"));
        assertThat(thingType.getProperties().get("key2"), is("value2"));
        assertThat(thingType.getRepresentationProperty(), is("uniqueId"));
        List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
        assertThat(channelDefinitions.size(), is(3));
        ChannelDefinition colorChannel = channelDefinitions.stream().filter(it -> "color".equals(it.getId())).findFirst().get();
        assertThat(colorChannel, is(notNullValue()));
        assertThat(colorChannel.getProperties().size(), is(2));
        assertThat(colorChannel.getProperties().get("chan.key1"), is("value1"));
        assertThat(colorChannel.getProperties().get("chan.key2"), is("value2"));
        ChannelType colorChannelType = channelTypeRegistry.getChannelType(colorChannel.getChannelTypeUID());
        assertThat(colorChannelType, is(notNullValue()));
        assertThat(colorChannelType.toString(), is("hue:color"));
        assertThat(colorChannelType.getItemType(), is("ColorItem"));
        assertThat(colorChannelType.getLabel(), is("HUE Lamp Color"));
        assertThat(colorChannelType.getDescription(), is("The color channel allows to control the color of the hue lamp. It is also possible to dim values and switch the lamp on and off."));
        Set<String> tags = colorChannelType.getTags();
        assertThat(tags, is(notNullValue()));
        assertThat(tags.contains("Hue"), is(true));
        assertThat(tags.contains("ColorLamp"), is(true));
        assertThat(tags.contains("AmbientLamp"), is(false));
        assertThat(tags.contains("AlarmSystem"), is(false));
        ChannelDefinition colorTemperatureChannel = channelDefinitions.stream().filter(it -> "color_temperature".equals(it.getId())).findFirst().get();
        assertThat(colorTemperatureChannel, is(notNullValue()));
        assertThat(colorTemperatureChannel.getProperties().size(), is(0));
        ChannelType colorTemperatureChannelType = channelTypeRegistry.getChannelType(colorTemperatureChannel.getChannelTypeUID());
        assertThat(colorTemperatureChannelType, is(notNullValue()));
        assertThat(colorTemperatureChannelType.toString(), is("hue:color_temperature"));
        assertThat(colorTemperatureChannelType.getItemType(), is("DimmerItem"));
        assertThat(colorTemperatureChannelType.getLabel(), is("HUE Lamp Color Temperature"));
        assertThat(colorTemperatureChannelType.getDescription(), is("The color temperature channel allows to set the color temperature from 0 (cold) to 100 (warm)."));
        tags = colorTemperatureChannelType.getTags();
        assertThat(tags, is(notNullValue()));
        assertThat(tags.contains("Hue"), is(true));
        assertThat(tags.contains("AmbientLamp"), is(true));
        assertThat(tags.contains("ColorLamp"), is(false));
        assertThat(tags.contains("AlarmSystem"), is(false));
        ChannelDefinition alarmChannel = channelDefinitions.stream().filter(it -> "alarm".equals(it.getId())).findFirst().get();
        assertThat(alarmChannel, is(notNullValue()));
        ChannelType alarmChannelType = channelTypeRegistry.getChannelType(alarmChannel.getChannelTypeUID());
        assertThat(alarmChannelType, is(notNullValue()));
        assertThat(alarmChannelType.toString(), is("hue:alarm"));
        assertThat(alarmChannelType.getItemType(), is(CoreItemFactory.NUMBER));
        assertThat(alarmChannelType.getLabel(), is("Alarm System"));
        assertThat(alarmChannelType.getDescription(), is("The light blinks if alarm is set."));
        tags = alarmChannelType.getTags();
        assertThat(tags, is(notNullValue()));
        assertThat(tags.contains("Hue"), is(true));
        assertThat(tags.contains("AlarmSystem"), is(true));
        assertThat(tags.contains("AmbientLamp"), is(false));
        assertThat(tags.contains("ColorLamp"), is(false));
        assertThat(alarmChannelType.getCategory(), is(equalTo("ALARM")));
        StateDescription state = alarmChannelType.getState();
        assertThat(state.getMinimum(), is(BigDecimal.ZERO));
        assertThat(state.getMaximum(), is(BigDecimal.valueOf(100.0)));
        assertThat(state.getStep(), is(BigDecimal.valueOf(10.0)));
        assertThat(state.getPattern(), is(equalTo("%d Peek")));
        assertThat(state.isReadOnly(), is(true));
        assertThat(state.getOptions().size(), is(2));
        assertThat(state.getOptions().get(0).getValue(), is(equalTo("SOUND")));
        assertThat(state.getOptions().get(0).getLabel(), is(equalTo("My great sound.")));
        // HUE Lamp with group
        thingType = thingTypes.stream().filter(it -> "hue:lamp-with-group".equals(it.toString())).findFirst().get();
        assertThat(thingType, is(notNullValue()));
        assertThat(thingType.getProperties().size(), is(0));
        assertThat(thingType.getCategory(), is(nullValue()));
        assertThat(thingType.isListed(), is(true));
        assertThat(thingType.getExtensibleChannelTypeIds(), containsInAnyOrder("brightness", "alarm"));
        List<ChannelGroupDefinition> channelGroupDefinitions = thingType.getChannelGroupDefinitions();
        assertThat(channelGroupDefinitions.size(), is(2));
        // Channel Group
        ChannelGroupDefinition channelGroupDefinition = channelGroupDefinitions.stream().filter(it -> "lampgroup".equals(it.getId())).findFirst().get();
        assertThat(channelGroupDefinition, is(notNullValue()));
        ChannelGroupType channelGroupType = channelGroupTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID());
        assertThat(channelGroupType, is(notNullValue()));
        channelDefinitions = channelGroupType.getChannelDefinitions();
        assertThat(channelDefinitions.size(), is(3));
        // Channel Group without channels
        channelGroupDefinition = channelGroupDefinitions.stream().filter(it -> "lampgroup-without-channels".equals(it.getId())).findFirst().get();
        assertThat(channelGroupDefinition, is(notNullValue()));
        channelGroupType = channelGroupTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID());
        assertThat(channelGroupType, is(notNullValue()));
        channelDefinitions = channelGroupType.getChannelDefinitions();
        assertThat(channelDefinitions.size(), is(0));
        // HUE Lamp without channels
        thingType = thingTypes.stream().filter(it -> "hue:lamp-without-channels".equals(it.toString())).findFirst().get();
        assertThat(thingType, is(notNullValue()));
        channelDefinitions = thingType.getChannelDefinitions();
        assertThat(channelDefinitions.size(), is(0));
    }
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) BeforeEach(org.junit.jupiter.api.BeforeEach) ChannelGroupType(org.openhab.core.thing.type.ChannelGroupType) ThingType(org.openhab.core.thing.type.ThingType) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition) IsIterableContainingInAnyOrder.containsInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder) Collection(java.util.Collection) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) StuffAddition(org.openhab.core.thing.xml.test.LoadedTestBundle.StuffAddition) Set(java.util.Set) StateDescription(org.openhab.core.types.StateDescription) BridgeType(org.openhab.core.thing.type.BridgeType) ChannelType(org.openhab.core.thing.type.ChannelType) Test(org.junit.jupiter.api.Test) ThingTypeProvider(org.openhab.core.thing.binding.ThingTypeProvider) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) BigDecimal(java.math.BigDecimal) List(java.util.List) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest) ChannelGroupTypeRegistry(org.openhab.core.thing.type.ChannelGroupTypeRegistry) CoreItemFactory(org.openhab.core.library.CoreItemFactory) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ChannelGroupType(org.openhab.core.thing.type.ChannelGroupType) ThingType(org.openhab.core.thing.type.ThingType) BridgeType(org.openhab.core.thing.type.BridgeType) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ChannelType(org.openhab.core.thing.type.ChannelType) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition) StateDescription(org.openhab.core.types.StateDescription) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 22 with ChannelDefinition

use of org.openhab.core.thing.type.ChannelDefinition in project openhab-core by openhab.

the class SystemWideChannelTypesTest method thingTyoesShouldHaveProperChannelDefinitions.

@Test
public void thingTyoesShouldHaveProperChannelDefinitions() throws Exception {
    try (final AutoCloseable unused = loadedSystemChannelsBundle()) {
        ThingType wirelessRouterType = thingTypeProvider.getThingTypes(null).stream().filter(it -> "SystemChannels:wireless-router".equals(it.getUID().getAsString())).findFirst().get();
        assertThat(wirelessRouterType, is(notNullValue()));
        Collection<ChannelDefinition> channelDefs = wirelessRouterType.getChannelDefinitions();
        assertThat(channelDefs.size(), is(3));
        ChannelDefinition myChannel = channelDefs.stream().filter(it -> "test".equals(it.getId()) && "system:my-channel".equals(it.getChannelTypeUID().getAsString())).findFirst().get();
        assertThat(myChannel, is(notNullValue()));
        ChannelDefinition sigStr = channelDefs.stream().filter(it -> "sigstr".equals(it.getId()) && "system:signal-strength".equals(it.getChannelTypeUID().getAsString())).findFirst().get();
        assertThat(sigStr, is(notNullValue()));
        ChannelDefinition lowBat = channelDefs.stream().filter(it -> "lowbat".equals(it.getId()) && "system:low-battery".equals(it.getChannelTypeUID().getAsString())).findFirst().get();
        assertThat(lowBat, is(notNullValue()));
    }
}
Also used : ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ThingType(org.openhab.core.thing.type.ThingType) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 23 with ChannelDefinition

use of org.openhab.core.thing.type.ChannelDefinition in project openhab-addons by openhab.

the class HomematicTypeGeneratorImpl method generate.

@Override
public void generate(HmDevice device) {
    if (thingTypeProvider != null) {
        ThingTypeUID thingTypeUID = UidUtils.generateThingTypeUID(device);
        ThingType tt = thingTypeProvider.getInternalThingType(thingTypeUID);
        if (tt == null || device.isGatewayExtras()) {
            logger.debug("Generating ThingType for device '{}' with {} datapoints", device.getType(), device.getDatapointCount());
            List<ChannelGroupType> groupTypes = new ArrayList<>();
            for (HmChannel channel : device.getChannels()) {
                List<ChannelDefinition> channelDefinitions = new ArrayList<>();
                // those will be populated dynamically during thing initialization
                if (!channel.isReconfigurable()) {
                    // generate channel
                    for (HmDatapoint dp : channel.getDatapoints()) {
                        if (!isIgnoredDatapoint(dp) && dp.getParamsetType() == HmParamsetType.VALUES) {
                            ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(dp);
                            ChannelType channelType = channelTypeProvider.getInternalChannelType(channelTypeUID);
                            if (channelType == null) {
                                channelType = createChannelType(dp, channelTypeUID);
                                channelTypeProvider.addChannelType(channelType);
                            }
                            ChannelDefinition channelDef = new ChannelDefinitionBuilder(dp.getName(), channelType.getUID()).build();
                            channelDefinitions.add(channelDef);
                        }
                    }
                }
                // generate group
                ChannelGroupTypeUID groupTypeUID = UidUtils.generateChannelGroupTypeUID(channel);
                ChannelGroupType groupType = channelGroupTypeProvider.getInternalChannelGroupType(groupTypeUID);
                if (groupType == null || device.isGatewayExtras()) {
                    String groupLabel = String.format("%s", channel.getType() == null ? null : MiscUtils.capitalize(channel.getType().replace("_", " ")));
                    groupType = ChannelGroupTypeBuilder.instance(groupTypeUID, groupLabel).withChannelDefinitions(channelDefinitions).build();
                    channelGroupTypeProvider.addChannelGroupType(groupType);
                    groupTypes.add(groupType);
                }
            }
            tt = createThingType(device, groupTypes);
            thingTypeProvider.addThingType(tt);
        }
        addFirmware(device);
    }
}
Also used : ChannelDefinitionBuilder(org.openhab.core.thing.type.ChannelDefinitionBuilder) ArrayList(java.util.ArrayList) ChannelGroupType(org.openhab.core.thing.type.ChannelGroupType) ChannelGroupTypeUID(org.openhab.core.thing.type.ChannelGroupTypeUID) ThingType(org.openhab.core.thing.type.ThingType) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) HmChannel(org.openhab.binding.homematic.internal.model.HmChannel) ChannelType(org.openhab.core.thing.type.ChannelType)

Example 24 with ChannelDefinition

use of org.openhab.core.thing.type.ChannelDefinition in project openhab-addons by openhab.

the class AbstractMieleThingHandlerTest method createChannelsForThingHandler.

private List<Channel> createChannelsForThingHandler(ThingTypeUID thingTypeUid, ThingUID thingUid) {
    ChannelTypeRegistry channelTypeRegistry = getService(ChannelTypeRegistry.class, ChannelTypeRegistry.class);
    assertNotNull(channelTypeRegistry);
    ThingTypeRegistry thingTypeRegistry = getService(ThingTypeRegistry.class, ThingTypeRegistry.class);
    assertNotNull(thingTypeRegistry);
    ThingType thingType = thingTypeRegistry.getThingType(thingTypeUid);
    assertNotNull(thingType);
    List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
    assertNotNull(channelDefinitions);
    List<Channel> channels = new ArrayList<Channel>();
    for (ChannelDefinition channelDefinition : channelDefinitions) {
        ChannelTypeUID channelTypeUid = channelDefinition.getChannelTypeUID();
        assertNotNull(channelTypeUid);
        ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUid);
        assertNotNull(channelType);
        String acceptedItemType = channelType.getItemType();
        assertNotNull(acceptedItemType);
        String channelId = channelDefinition.getId();
        assertNotNull(channelId);
        ChannelUID channelUid = new ChannelUID(thingUid, channelId);
        assertNotNull(channelUid);
        Channel channel = ChannelBuilder.create(channelUid, acceptedItemType).build();
        assertNotNull(channel);
        channels.add(channel);
    }
    return channels;
}
Also used : ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) ArrayList(java.util.ArrayList) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ThingType(org.openhab.core.thing.type.ThingType) ChannelType(org.openhab.core.thing.type.ChannelType)

Aggregations

ChannelDefinition (org.openhab.core.thing.type.ChannelDefinition)24 ChannelType (org.openhab.core.thing.type.ChannelType)13 ThingType (org.openhab.core.thing.type.ThingType)12 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)10 ArrayList (java.util.ArrayList)9 Test (org.junit.jupiter.api.Test)9 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)9 ChannelDefinitionBuilder (org.openhab.core.thing.type.ChannelDefinitionBuilder)9 ChannelGroupType (org.openhab.core.thing.type.ChannelGroupType)8 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)7 ChannelGroupDefinition (org.openhab.core.thing.type.ChannelGroupDefinition)7 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Collection (java.util.Collection)4 ChannelGroupTypeUID (org.openhab.core.thing.type.ChannelGroupTypeUID)4 URI (java.net.URI)3 List (java.util.List)3 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)3 CoreMatchers (org.hamcrest.CoreMatchers)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Channel (org.openhab.core.thing.Channel)3