Channels cannot be linked if dynamically created [message #1752648] |
Wed, 25 January 2017 18:54 |
Markus Eckhardt Messages: 2 Registered: January 2017 |
Junior Member |
|
|
Hi,
maybe it's a bug or I do something wrong, so I need a bit help.
I'm creating channels in the initialization of a thing. The creation is working and the created channels are appearing. (Between 2-15 Channels in a List).
The problem is, if I start PaperUI then I cannot link them to a item. I I'm push the button but nothing happen.
If the simple mode is on, then the items are created and they are working like expected.
public void initialize() {
.
.
List<Channel> subChannels = new ArrayList<Channel>();
.
// In a loop
Channel newChannel = ChannelBuilder
.create(new ChannelUID(thing.getUID(), subKey), "Number")
.withType(new ChannelTypeUID(thing.getUID().getBindingId(), CHANNEL_FLOAT_VALUE)) .withDescription(subKey).withLabel(subKey).withKind(ChannelKind.STATE).build();
logger.info("create: {}", thing.getUID());
.
.
subChannels.add(newChannel);
.
.
ThingBuilder thingBuilder = editThing();
thingBuilder.withChannels(subChannels);
updateThing(thingBuilder.build());
Any ideas?
Markus
[Updated on: Wed, 25 January 2017 19:49] Report message to a moderator
|
|
|
|
|
Re: Channels cannot be linked if dynamically created [message #1759268 is a reply to message #1752648] |
Sun, 09 April 2017 15:57 |
Charles Brouwers Messages: 7 Registered: April 2017 |
Junior Member |
|
|
I ran into a similar issue. Dynamically created channels were linking in simple mode (Paper UI) but nothing would happened when I tried manually. Digging into the UI java code, i realized it was because controllers.min.js that manages the linking process on the client side checks the ChannelTypeUID of the channel to be linked against a list maintained in a variable called channelTypes. I haven't done extensive testing but i assume channelTypes is initialized at startup and doesn't reflect any new ChannelTypeUID created dynamically. In other words, you can create channels dynamically but not channel types ! Not sure, it is true but at least it inspired the following approach that is working for me:
1. Define all your channel types in the binding's thing_types.xml file with channel-type clauses. Let's assume you use "waterlevel" as for the channel type id.
<channel-type id="waterlevel" advanced="true">
<item-type>Number</item-type>
<label>Water Level</label>
<state readOnly="true" pattern="%.1f °F"></state>
</channel-type>
2. Declare and initialize a constant ChannelTypeUID using the is.
public final static ChannelTypeUID waterlevelTypeUID = new ChannelTypeUID(BINDING_ID, "waterlevel");
3. Modify your ChannelBuilder call to refer to this ChannelTypeUID:
.withType(waterlevelTypeUID )
By the way, this approach let's you define general aspects of the channel type (description, formatting, readonly, ... ) in the the XML file, which feels easier to me than doing so in the code.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03662 seconds