I would like to add channels at runtime depending on the capability of the device.
Now I understand that I can add channels dynamically using:
ThingBuilder thingBuilder = editThing();
ChannelUID channelUID = new ChannelUID(getThing().getUID(), capability.getChannel());
ChannelTypeUID channelTypeUID = new ChannelTypeUID(capability.getChannel());
Channel channel = ChannelBuilder.create(channelUID, “String”).build();
thingBuilder.withChannel(channel);
updateThing(thingBuilder.build());
But I would like to avoid defining the channels from scratch, instead adding channelstypes already available in the binding XML definitions in ESH-INF
Is there a way to archive that?
Note… the not elegant way would be to always add them to the thing from the start and to remove all not needed channels later onwards, but that seems quite confusing to me for a user, if channels are there and minutes later they are gone (when the thing is fully operational and we know which channels to add/remove).