Search in sources :

Example 6 with ChannelDefinitionBuilder

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

the class ThingFactoryTest method createThingWithChannels.

@Test
public void createThingWithChannels() {
    ChannelType channelType1 = ChannelTypeBuilder.state(new ChannelTypeUID("bindingId:channelTypeId1"), "channelLabel", "Color").withTags(Stream.of("tag1", "tag2").collect(toSet())).build();
    ChannelType channelType2 = ChannelTypeBuilder.state(new ChannelTypeUID("bindingId:channelTypeId2"), "channelLabel2", "Dimmer").withTag("tag3").build();
    registerChannelTypes(Stream.of(channelType1, channelType2).collect(toSet()), emptyList());
    ChannelDefinition channelDef1 = new ChannelDefinitionBuilder("ch1", channelType1.getUID()).build();
    ChannelDefinition channelDef2 = new ChannelDefinitionBuilder("ch2", channelType2.getUID()).build();
    ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("bindingId:thingType"), "label").withSupportedBridgeTypeUIDs(emptyList()).withChannelDefinitions(Stream.of(channelDef1, channelDef2).collect(toList())).build();
    Configuration configuration = new Configuration();
    Thing thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), configuration);
    assertThat(thing.getChannels().size(), is(2));
    assertThat(thing.getChannels().get(0).getUID().toString(), is(equalTo("bindingId:thingType:thingId:ch1")));
    assertThat(thing.getChannels().get(0).getAcceptedItemType(), is(equalTo("Color")));
    assertThat(thing.getChannels().get(0).getDefaultTags().contains("tag1"), is(true));
    assertThat(thing.getChannels().get(0).getDefaultTags().contains("tag2"), is(true));
    assertThat(thing.getChannels().get(0).getDefaultTags().contains("tag3"), is(false));
    assertThat(thing.getChannels().get(1).getDefaultTags().contains("tag1"), is(false));
    assertThat(thing.getChannels().get(1).getDefaultTags().contains("tag2"), is(false));
    assertThat(thing.getChannels().get(1).getDefaultTags().contains("tag3"), is(true));
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Thing(org.eclipse.smarthome.core.thing.Thing) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 7 with ChannelDefinitionBuilder

use of org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder 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());
    }
    return new ChannelDefinitionBuilder(id, new ChannelTypeUID(typeUID)).withProperties(propertiesMap).withLabel(getLabel()).withDescription(getDescription()).withAutoUpdatePolicy(getAutoUpdatePolicy()).build();
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) NodeValue(org.eclipse.smarthome.config.xml.util.NodeValue) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) HashMap(java.util.HashMap)

Example 8 with ChannelDefinitionBuilder

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

the class ChangeThingTypeOSGiTest method getChannelDefinitions.

private List<ChannelDefinition> getChannelDefinitions(ThingTypeUID thingTypeUID) throws URISyntaxException {
    List<ChannelDefinition> channelDefinitions = new ArrayList<>();
    ChannelTypeUID channelTypeUID = new ChannelTypeUID("test:" + thingTypeUID.getId());
    ChannelType channelType = new ChannelType(channelTypeUID, false, "itemType", "channelLabel", "description", "category", new HashSet<String>(), null, new URI("scheme", "channelType:" + thingTypeUID.getId(), null));
    channelTypes.put(channelTypeUID, channelType);
    ChannelDefinition cd = new ChannelDefinitionBuilder("channel" + thingTypeUID.getId(), channelTypeUID).build();
    channelDefinitions.add(cd);
    return channelDefinitions;
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) URI(java.net.URI)

Example 9 with ChannelDefinitionBuilder

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

the class ThingFactoryTest method createThingWithChannelsGroups.

@Test
public void createThingWithChannelsGroups() {
    ChannelType channelType1 = ChannelTypeBuilder.state(new ChannelTypeUID("bindingId:channelTypeId1"), "channelLabel", "Color").withTags(Stream.of("tag1", "tag2").collect(toSet())).build();
    ChannelType channelType2 = ChannelTypeBuilder.state(new ChannelTypeUID("bindingId:channelTypeId2"), "channelLabel2", "Dimmer").withTag("tag3").build();
    ChannelDefinition channelDef1 = new ChannelDefinitionBuilder("ch1", channelType1.getUID()).build();
    ChannelDefinition channelDef2 = new ChannelDefinitionBuilder("ch2", channelType2.getUID()).build();
    ChannelGroupType channelGroupType1 = ChannelGroupTypeBuilder.instance(new ChannelGroupTypeUID("bindingid:groupTypeId1"), "label").isAdvanced(false).withDescription("description").withCategory("myCategory1").withChannelDefinitions(Stream.of(channelDef1, channelDef2).collect(toList())).build();
    ChannelGroupType channelGroupType2 = ChannelGroupTypeBuilder.instance(new ChannelGroupTypeUID("bindingid:groupTypeId2"), "label").isAdvanced(false).withDescription("description").withCategory("myCategory2").withChannelDefinitions(singletonList(channelDef1)).build();
    ChannelGroupDefinition channelGroupDef1 = new ChannelGroupDefinition("group1", channelGroupType1.getUID());
    ChannelGroupDefinition channelGroupDef2 = new ChannelGroupDefinition("group2", channelGroupType2.getUID());
    registerChannelTypes(Stream.of(channelType1, channelType2).collect(toSet()), Stream.of(channelGroupType1, channelGroupType2).collect(toSet()));
    ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("bindingId:thingType"), "label").withSupportedBridgeTypeUIDs(emptyList()).withChannelGroupDefinitions(Stream.of(channelGroupDef1, channelGroupDef2).collect(toList())).build();
    Configuration configuration = new Configuration();
    Thing thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), configuration);
    assertThat(thing.getChannels().size(), is(3));
    assertThat(thing.getChannels().get(0).getUID().toString(), is(equalTo("bindingId:thingType:thingId:group1#ch1")));
    assertThat(thing.getChannels().get(1).getUID().toString(), is(equalTo("bindingId:thingType:thingId:group1#ch2")));
    assertThat(thing.getChannels().get(2).getUID().toString(), is(equalTo("bindingId:thingType:thingId:group2#ch1")));
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ChannelGroupDefinition(org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition) Thing(org.eclipse.smarthome.core.thing.Thing) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 10 with ChannelDefinitionBuilder

use of org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder 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 ChannelDefinitionBuilder(CHANNEL_ID, CHANNEL_TYPE_UID).build())).build();
    ThingTypeProvider mockThingTypeProvider = mock(ThingTypeProvider.class);
    when(mockThingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(thingType);
    registerService(mockThingTypeProvider);
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) ThingTypeProvider(org.eclipse.smarthome.core.thing.binding.ThingTypeProvider)

Aggregations

ChannelDefinitionBuilder (org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder)12 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)10 ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)8 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)8 ArrayList (java.util.ArrayList)5 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)5 ThingType (org.eclipse.smarthome.core.thing.type.ThingType)5 URI (java.net.URI)3 Configuration (org.eclipse.smarthome.config.core.Configuration)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)3 ChannelGroupType (org.eclipse.smarthome.core.thing.type.ChannelGroupType)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Test (org.junit.Test)3 Locale (java.util.Locale)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)2 Channel (org.eclipse.smarthome.core.thing.Channel)2 BaseThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory)2 ThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory)2