Dynamically adding channels/channel groups from XML

I’m stumped and would really appreciate some help. I and working on a binding for the Bond Home RF bridge for controlling ceiling fans, fireplaces, shades, and other RF things. There are a lot of possible “channels” for each device depending on the configuration of the fan - ie, some have lights or not, some lights are dimmable via a set brightness command, others you can only increase/decrease brightness but not set a value, etc. For each device that’s been programmed into the Bond Bridge, I can get from the Bond API exactly what commands are available.

Here is my device handler: https://github.com/SRGDamia1/openhab2-addons/blob/bondhome/bundles/org.openhab.binding.bondhome/src/main/java/org/openhab/binding/bondhome/internal/handler/BondDeviceHandler.java

Here is what I want the result to look like:

  • 4 available thing types for the binding, based on those supported by Bond (fan, fireplace, shades, generic) - this I have no trouble with via xml.
  • For each device channels are created only based on what commands are actually possible for that device (ie, no light channels for lightless fans)
  • The channels for each device are grouped nicely so that it is easy to manage the channels in places like PaperUI.

Here’s what I’ve tried, and my results:

  • Creating channel groups and channel types in XML, adding channels with thing builder that reference the UID’s of those channel types - this doesn’t work - the channels aren’t grouped, they don’t actually link to the XML channels, and when I test in PaperUI and try to link the channels I cannot create a link
  • Creating a channel group type provider and channel type provider and creating channels based on those - channels still don’t end up grouped and, again, cannot be linked in PaperUI

When I say “cannot be linked” I mean that I can see the channels and ostensibly add a link to an item, but there are no “profiles” available on which to base the link - the drop-down box in Paper UI is just empty. So the link is never made.

Is there a way to do what I want? Would it be better to list all possible groups and channel types in the thing type xml and then take away the ones that don’t apply? I haven’t tried that yet because I thought I read somewhere that the channels in the thing type xml should only be ones that are guaranteed to be there. Am I incorrect in that? If any one has a reference binding to look at, I’d really appreciate it!

Thank you so much for your help!