Hello All,
I'm having trouble creating channel groups dynamically. My binding consists of a bridge with 1 or more device things with 1 or more channels. The device thing and channels are created dynamically.
My Device Type and Channel type look like so:
<thing-type id="device">
<supported-bridge-type-refs>
<bridge-type-ref id="harmonyHub" />
</supported-bridge-type-refs>
<label>Harmony Device</label>
<description>Logitech Harmony Hub Device</description>
<properties>
<property name="name"></property>
</properties>
<config-description>
<parameter name="id" type="integer" required="true">
<label>id</label>
<description>Numeric ID of the Harmony Device</description>
</parameter>
</config-description>
</thing-type>
<channel-type id="sendButtonPress">
<item-type>Switch</item-type>
<label>Button Press</label>
<description>Sends a button press to the device</description>
<config-description>
<parameter name="buttonName" type="text"></parameter>
</config-description>
</channel-type>
You will notice that the device does not link to a channel in the XML file, this is because a device can have 1 or more (usually a lot more) "sendButtonPress" channels. This is working fine with the following code as well as registering a ChannelTypeProvider:
ThingBuilder thingBuilder = editThing();
.......
Map<String, String> channelProperties = new HashMap<String, String>();
channelProperties.put("buttonName", function.getName());
ChannelTypeUID channelTypeUID = new ChannelTypeUID(HarmonyHubBindingConstants.BINDING_ID,
HarmonyHubBindingConstants.CHANNEL_SEND_BUTTON_PRESS);
Channel channel = ChannelBuilder
.create(new ChannelUID(getThing().getUID(), function.getName()), "String")
.withType(channelTypeUID).withProperties(channelProperties).build();
thingBuilder.withChannel(channel);
The Logitech Harmony hub groups these button presses into "control groups" which seem to map nicely to channel groups. The name and number of these groups is not known until I query the device. So I would like to now create channel groups dynamically and link those to a device. Unfortunately I don't think I fully understand the relationship between ChannelGroupTypes Channels and ChannelDefinitions . I have been playing around with the following code :
ArrayList<ChannelDefinition> channelDefinitions = new ArrayList<ChannelDefinition>();
.....
ChannelDefinition cd = new ChannelDefinition(channel.getUID().getId(), channelTypeUID);
channelDefinitions.add(cd);
.......
ChannelGroupTypeUID groupTypeUID = new ChannelGroupTypeUID(HarmonyHubBindingConstants.BINDING_ID,
controlGroup.getName());
ChannelGroupType groupType = new ChannelGroupType(groupTypeUID, false, controlGroup.getName(),
controlGroup.getName() + " Channel Group", channelDefinitions);
I'm using the ChannelTypeProvider to return the newly created ChannelGroupType, but this never seems to be called (unlike my dynamic channels which are working) I'm guessing I'm missing something with the relationship between a ChannelDefinition and the Channel I create dynamically. I also don't understand how a ChannelGroup is tied to a Thing and then how channels are tied to a ChannelGroup. This is clear in the XML, but not in code.
Thanks!