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));
}
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();
}
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;
}
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")));
}
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);
}
Aggregations