Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Channels cannot be linked if dynamically created
Channels cannot be linked if dynamically created [message #1752648] Wed, 25 January 2017 18:54 Go to next message
Markus Eckhardt is currently offline Markus EckhardtFriend
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 #1753349 is a reply to message #1752648] Sat, 04 February 2017 10:02 Go to previous messageGo to next message
Markus Rathgeb is currently offline Markus RathgebFriend
Messages: 105
Registered: August 2014
Senior Member

Can you give it a try using the REST API yourself?
So, if it is working using the REST API, it is a bug in the PaperUI.
Re: Channels cannot be linked if dynamically created [message #1753846 is a reply to message #1752648] Fri, 10 February 2017 16:36 Go to previous messageGo to next message
Patrick Hecker is currently offline Patrick HeckerFriend
Messages: 1
Registered: February 2017
Junior Member
Hi,

I have created an issue for this: https://github.com/eclipse/smarthome/issues/2903

This should be fixed by #2949. But the change is not yet in the snapshot build.

Patrick
Re: Channels cannot be linked if dynamically created [message #1759268 is a reply to message #1752648] Sun, 09 April 2017 15:57 Go to previous messageGo to next message
Charles Brouwers is currently offline Charles BrouwersFriend
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.
Re: Channels cannot be linked if dynamically created [message #1759318 is a reply to message #1759268] Mon, 10 April 2017 13:47 Go to previous message
Simon Kaufmann is currently offline Simon KaufmannFriend
Messages: 51
Registered: January 2011
Member
Quote:
which feels easier to me than doing so in the code.


Nice to read that! This the recommended approach for use-cases like yours, where you have (dynamic) Channels with ChannelTypes that you know in advance. Would be different of course if the ChannelTypes are dynamic too...

Afaik there are no events fired when new ChannelTypes are showing up, hence the framework would need to be enhanced first otherwise. So I'm glad you are happy with the current solution.
Previous Topic:Is it ok to use Thread.sleep() in binding
Next Topic:Best update strategy for a polled device ?
Goto Forum:
  


Current Time: Sat Dec 07 23:22:23 GMT 2024

Powered by FUDForum. Page generated in 0.03662 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top