Search in sources :

Example 6 with ChannelDefinition

use of org.eclipse.smarthome.core.thing.type.ChannelDefinition in project smarthome by eclipse.

the class ChannelXmlResult method toChannelDefinition.

protected ChannelDefinition toChannelDefinition(String bindingId) throws ConversionException {
    String id = getId();
    String typeId = getTypeId();
    String typeUID = getTypeUID(bindingId, typeId);
    // Convert the channel properties into a map
    Map<String, String> propertiesMap = new HashMap<>();
    for (NodeValue property : getProperties()) {
        propertiesMap.put(property.getAttributes().get("name"), (String) property.getValue());
    }
    ChannelDefinition channelDefinition = new ChannelDefinition(id, new ChannelTypeUID(typeUID), propertiesMap, getLabel(), getDescription());
    return channelDefinition;
}
Also used : NodeValue(org.eclipse.smarthome.config.xml.util.NodeValue) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) HashMap(java.util.HashMap) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition)

Example 7 with ChannelDefinition

use of org.eclipse.smarthome.core.thing.type.ChannelDefinition in project smarthome by eclipse.

the class DsDeviceThingTypeProvider method getThingType.

@Override
public ThingType getThingType(ThingTypeUID thingTypeUID, Locale locale) {
    try {
        SupportedThingTypes supportedThingType = SupportedThingTypes.valueOf(thingTypeUID.getId());
        ThingTypeBuilder thingTypeBuilder = ThingTypeBuilder.instance(thingTypeUID, getLabelText(thingTypeUID.getId(), locale)).withSupportedBridgeTypeUIDs(Arrays.asList(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE.getAsString())).withDescription(getDescText(thingTypeUID.getId(), locale));
        try {
            if (supportedThingType.havePowerSensors) {
                thingTypeBuilder.withConfigDescriptionURI(new URI(DEVICE_WITH_POWER_SENSORS));
            } else {
                thingTypeBuilder.withConfigDescriptionURI(new URI(DEVICE_WITHOUT_POWER_SENSORS));
            }
        } catch (URISyntaxException e) {
            logger.debug("An URISyntaxException occurred: ", e);
        }
        if (SupportedThingTypes.GR.equals(supportedThingType)) {
            thingTypeBuilder.withChannelDefinitions(Arrays.asList(new ChannelDefinition(DsChannelTypeProvider.SHADE, new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, DsChannelTypeProvider.SHADE))));
        }
        if (SupportedThingTypes.circuit.equals(supportedThingType)) {
            List<ChannelDefinition> channelDefinitions = new ArrayList<ChannelDefinition>(3);
            for (MeteringTypeEnum meteringType : MeteringTypeEnum.values()) {
                channelDefinitions.add(new ChannelDefinition(DsChannelTypeProvider.getMeteringChannelID(meteringType, MeteringUnitsEnum.WH, false), new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, DsChannelTypeProvider.getMeteringChannelID(meteringType, MeteringUnitsEnum.WH, false))));
            }
            thingTypeBuilder.withChannelDefinitions(channelDefinitions);
        }
        return thingTypeBuilder.build();
    } catch (IllegalArgumentException e) {
    // ignore
    }
    return null;
}
Also used : ThingTypeBuilder(org.eclipse.smarthome.core.thing.type.ThingTypeBuilder) MeteringTypeEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.MeteringTypeEnum) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 8 with ChannelDefinition

use of org.eclipse.smarthome.core.thing.type.ChannelDefinition in project smarthome by eclipse.

the class ChannelStateDescriptionProviderOSGiTest method setup.

@Before
public void setup() {
    initMocks(this);
    Mockito.when(componentContext.getBundleContext()).thenReturn(bundleContext);
    registerVolatileStorageService();
    itemRegistry = getService(ItemRegistry.class);
    assertNotNull(itemRegistry);
    final TestThingHandlerFactory thingHandlerFactory = new TestThingHandlerFactory();
    thingHandlerFactory.activate(componentContext);
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
    final StateDescription state = new StateDescription(BigDecimal.ZERO, BigDecimal.valueOf(100), BigDecimal.TEN, "%d Peek", true, Collections.singletonList(new StateOption("SOUND", "My great sound.")));
    final StateDescription state2 = new StateDescription(BigDecimal.ZERO, BigDecimal.valueOf(256), BigDecimal.valueOf(8), null, false, null);
    final ChannelType channelType = new ChannelType(new ChannelTypeUID("hue:alarm"), false, "Number", " ", "", null, null, state, null);
    final ChannelType channelType2 = new ChannelType(new ChannelTypeUID("hue:num"), false, "Number", " ", "", null, null, state2, null);
    final ChannelType channelType3 = new ChannelType(new ChannelTypeUID("hue:info"), true, "String", " ", "", null, null, null, null);
    final ChannelType channelType4 = new ChannelType(new ChannelTypeUID("hue:color"), false, "Color", "Color", "", "ColorLight", null, null, null);
    final ChannelType channelType5 = new ChannelType(new ChannelTypeUID("hue:brightness"), false, "Dimmer", "Brightness", "", "DimmableLight", null, null, null);
    final ChannelType channelType6 = new ChannelType(new ChannelTypeUID("hue:switch"), false, "Switch", "Switch", "", "Light", null, null, null);
    final ChannelType channelType7 = new ChannelType(new ChannelTypeUID("hue:num-dynamic"), false, "Number", " ", "", "Light", null, state, null);
    List<ChannelType> channelTypes = new ArrayList<>();
    channelTypes.add(channelType);
    channelTypes.add(channelType2);
    channelTypes.add(channelType3);
    channelTypes.add(channelType4);
    channelTypes.add(channelType5);
    channelTypes.add(channelType6);
    channelTypes.add(channelType7);
    registerService(new ChannelTypeProvider() {

        @Override
        public Collection<ChannelType> getChannelTypes(Locale locale) {
            return channelTypes;
        }

        @Override
        public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) {
            for (final ChannelType channelType : channelTypes) {
                if (channelType.getUID().equals(channelTypeUID)) {
                    return channelType;
                }
            }
            return null;
        }

        @Override
        public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) {
            return null;
        }

        @Override
        public Collection<ChannelGroupType> getChannelGroupTypes(Locale locale) {
            return Collections.emptySet();
        }
    });
    registerService(new DynamicStateDescriptionProvider() {

        final StateDescription newState = new StateDescription(BigDecimal.valueOf(10), BigDecimal.valueOf(100), BigDecimal.valueOf(5), "VALUE %d", false, Arrays.asList(new StateOption("value0", "label0"), new StateOption("value1", "label1")));

        @Override
        @Nullable
        public StateDescription getStateDescription(@NonNull Channel channel, @Nullable StateDescription original, @Nullable Locale locale) {
            String id = channel.getUID().getIdWithoutGroup();
            if ("7_1".equals(id)) {
                assertEquals(channel.getChannelTypeUID(), channelType7.getUID());
                return newState;
            } else if ("7_2".equals(id)) {
                assertEquals(channel.getChannelTypeUID(), channelType7.getUID());
                StateDescription newState2 = new StateDescription(original.getMinimum().add(BigDecimal.ONE), original.getMaximum().add(BigDecimal.ONE), original.getStep().add(BigDecimal.TEN), "NEW " + original.getPattern(), true, original.getOptions());
                return newState2;
            }
            return null;
        }
    });
    List<ChannelDefinition> channelDefinitions = new ArrayList<>();
    channelDefinitions.add(new ChannelDefinition("1", channelType.getUID()));
    channelDefinitions.add(new ChannelDefinition("2", channelType2.getUID()));
    channelDefinitions.add(new ChannelDefinition("3", channelType3.getUID()));
    channelDefinitions.add(new ChannelDefinition("4", channelType4.getUID()));
    channelDefinitions.add(new ChannelDefinition("5", channelType5.getUID()));
    channelDefinitions.add(new ChannelDefinition("6", channelType6.getUID()));
    channelDefinitions.add(new ChannelDefinition("7_1", channelType7.getUID()));
    channelDefinitions.add(new ChannelDefinition("7_2", channelType7.getUID()));
    registerService(new SimpleThingTypeProvider(Collections.singleton(ThingTypeBuilder.instance(new ThingTypeUID("hue:lamp"), "label").withChannelDefinitions(channelDefinitions).build())));
    List<Item> items = new ArrayList<>();
    items.add(new NumberItem("TestItem"));
    items.add(new NumberItem("TestItem2"));
    items.add(new StringItem("TestItem3"));
    items.add(new ColorItem("TestItem4"));
    items.add(new DimmerItem("TestItem5"));
    items.add(new SwitchItem("TestItem6"));
    items.add(new NumberItem("TestItem7_1"));
    items.add(new NumberItem("TestItem7_2"));
    registerService(new TestItemProvider(items));
    linkRegistry = getService(ItemChannelLinkRegistry.class);
    stateDescriptionProvider = getService(StateDescriptionProvider.class);
    assertNotNull(stateDescriptionProvider);
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) DynamicStateDescriptionProvider(org.eclipse.smarthome.core.thing.type.DynamicStateDescriptionProvider) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Item(org.eclipse.smarthome.core.items.Item) StringItem(org.eclipse.smarthome.core.library.items.StringItem) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Channel(org.eclipse.smarthome.core.thing.Channel) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) StringItem(org.eclipse.smarthome.core.library.items.StringItem) StateOption(org.eclipse.smarthome.core.types.StateOption) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) Collection(java.util.Collection) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateDescriptionProvider(org.eclipse.smarthome.core.types.StateDescriptionProvider) DynamicStateDescriptionProvider(org.eclipse.smarthome.core.thing.type.DynamicStateDescriptionProvider) Nullable(org.eclipse.jdt.annotation.Nullable) Before(org.junit.Before)

Example 9 with ChannelDefinition

use of org.eclipse.smarthome.core.thing.type.ChannelDefinition in project smarthome by eclipse.

the class ThingManagerOSGiJavaTest method registerThingTypeProvider.

private void registerThingTypeProvider() throws Exception {
    ThingType thingType = ThingTypeBuilder.instance(THING_TYPE_UID, "label").withConfigDescriptionURI(CONFIG_DESCRIPTION_THING).withChannelDefinitions(Collections.singletonList(new ChannelDefinition("channel", CHANNEL_TYPE_UID))).build();
    ThingTypeProvider mockThingTypeProvider = mock(ThingTypeProvider.class);
    when(mockThingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(thingType);
    registerService(mockThingTypeProvider);
}
Also used : ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ThingTypeProvider(org.eclipse.smarthome.core.thing.binding.ThingTypeProvider)

Example 10 with ChannelDefinition

use of org.eclipse.smarthome.core.thing.type.ChannelDefinition in project smarthome by eclipse.

the class SystemChannelsInChannelGroupsTest method thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDefinitions.

@Test
public void thingTypesWithSystemChannelsInChannelsGoupsShouldHavePorperChannelDefinitions() throws Exception {
    // install test bundle
    Bundle sysBundle = SyntheticBundleInstaller.install(bundleContext, SYSTEM_CHANNELS_IN_CHANNEL_GROUPS_BUNDLE_NAME);
    assertThat(sysBundle, is(notNullValue()));
    List<ThingType> thingTypes = thingTypeProvider.getThingTypes(null).stream().filter(it -> it.getUID().getId().equals("wireless-router")).collect(Collectors.toList());
    assertThat(thingTypes.size(), is(1));
    List<ChannelGroupType> channelGroupTypes = channelTypeRegistry.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 -> it.getId().equals("test") && it.getChannelTypeUID().getAsString().equals("system:my-channel")).collect(Collectors.toList());
    List<ChannelDefinition> sigStr = channelDefs.stream().filter(it -> it.getId().equals("sigstr") && it.getChannelTypeUID().getAsString().equals("system:signal-strength")).collect(Collectors.toList());
    List<ChannelDefinition> lowBat = channelDefs.stream().filter(it -> it.getId().equals("lowbat") && it.getChannelTypeUID().getAsString().equals("system:low-battery")).collect(Collectors.toList());
    assertThat(myChannel.size(), is(1));
    assertThat(sigStr.size(), is(1));
    assertThat(lowBat.size(), is(1));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Collection(java.util.Collection) SyntheticBundleInstaller(org.eclipse.smarthome.test.SyntheticBundleInstaller) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Assert.assertThat(org.junit.Assert.assertThat) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) List(java.util.List) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelTypeRegistry(org.eclipse.smarthome.core.thing.type.ChannelTypeRegistry) ThingTypeProvider(org.eclipse.smarthome.core.thing.binding.ThingTypeProvider) After(org.junit.After) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Bundle(org.osgi.framework.Bundle) Before(org.junit.Before) Bundle(org.osgi.framework.Bundle) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

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