Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Updating the Thing Structure
Updating the Thing Structure [message #1699380] Tue, 23 June 2015 21:33 Go to next message
Haris Sibonjic is currently offline Haris SibonjicFriend
Messages: 6
Registered: April 2015
Junior Member
Hi, guys.

I want to implement binding of a thing that has different numbers of channels, all channels are Switch type, but the number of switches are different from one thing to another, so I need a way to construct thing with channels dynamically.

I found that ThingBuilder is used for updating the structure of a thing from this link:
https://github.com/eclipse/smarthome/blob/master/docs/sources/architecture/thing-handler.md

protected void thingStructureChanged() {
ThingBuilder thingBuilder = editThing();
Channel channel = ChannelBuilder.create(new ChannelUID("bindingId:type:thingId:1"), "String").build();
thingBuilder.withChannel(channel);
updateThing(thingBuilder.build());
}

but i cant find the methods used in the example above.
https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/ThingBuilder.java

So, what is the best was to add manually channels.
Thanks in advance, Haris.
Re: Updating the Thing Structure [message #1699685 is a reply to message #1699380] Thu, 25 June 2015 19:31 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Hi Haris,

the methods are defined in the base class (https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/GenericThingBuilder.java).

So it is possible to use the ThingBuilder exactly as documented in the referenced documentation.

Regards

Dennis
Re: Updating the Thing Structure [message #1708007 is a reply to message #1699685] Fri, 11 September 2015 12:00 Go to previous messageGo to next message
Haris Sibonjic is currently offline Haris SibonjicFriend
Messages: 6
Registered: April 2015
Junior Member
Hi Dennis,
Thanks for your reply. I added the following code, but when calling the function I am getting this error:

at com.google.common.collect.ImmutableCollection.add(ImmutableCollection.java:91)
at org.eclipse.smarthome.core.thing.binding.builder.GenericThingBuilder.withChannel(GenericThingBuilder.java:31)
at org.openhab.binding.lirc.handler.LircHandler.thingStructureChanged(LircHandler.java:47)
at org.openhab.binding.lirc.handler.LircHandler.initialize(LircHandler.java:62)
at org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory.registerHandler(BaseThingHandlerFactory.java:116)
at org.eclipse.smarthome.core.thing.internal.ThingManager$6.call(ThingManager.java:448)
at org.eclipse.smarthome.core.thing.internal.ThingManager$6.call(ThingManager.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

I am calling the function in thinghandler. Am I missing something?
I am trying to build a binding for Lirc (linux infrared) on my rpi .

Best regards, Haris
Re: Updating the Thing Structure [message #1708164 is a reply to message #1708007] Mon, 14 September 2015 10:23 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
I would assume that this is a bug - I guess that
https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/GenericThingBuilder.java#L41
should be implemented the same way as
https://github.com/eclipse/smarthome/blob/master/bundles/core/org.eclipse.smarthome.core.thing/src/main/java/org/eclipse/smarthome/core/thing/binding/builder/GenericThingBuilder.java#L36

Dennis, can you confirm?
Re: Updating the Thing Structure [message #1708170 is a reply to message #1708164] Mon, 14 September 2015 10:58 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Yes, I can confirm that. I will create a fix soon.
Re: Updating the Thing Structure [message #1708171 is a reply to message #1708170] Mon, 14 September 2015 11:15 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
Fixed, thanks: https://github.com/eclipse/smarthome/pull/452
Re: Updating the Thing Structure [message #1708352 is a reply to message #1699380] Tue, 15 September 2015 18:51 Go to previous messageGo to next message
Haris Sibonjic is currently offline Haris SibonjicFriend
Messages: 6
Registered: April 2015
Junior Member
Hi,

Thanks for fast reply. I tried today to add channels, and it works but now I have a different issue, the new channels are not displayed in Paper UI. I am calling the thingStructureChanged() within the initialize() method of thingHandler. The channels are displayed in REST API

{
    "statusInfo": {
      "status": "ONLINE",
      "statusDetail": "NONE"
    },
    "item": {
      "members": [],
      "link": "http://localhost:8080/rest/items/lirc_remote_9542a251",
      "state": "NULL",
      "type": "GroupItem",
      "name": "lirc_remote_9542a251",
      "label": "lirc Binding Thing",
      "tags": [
        "thing"
      ],
      "groupNames": [
        "gFF"
      ]
    },
    "configuration": {},
    "properties": {},
    "UID": "lirc:remote:9542a251",
    "channels": [
      {
        "linkedItems": [],
        "id": "0",
        "itemType": "Switch",
        "properties": {}
      },
      {
        "linkedItems": [],
        "id": "test",
        "itemType": "String",
        "properties": {}
      }
    ]
  },


I see that my new channels are not linked, like is it the case with other hard coded channels. Am I missing something?

[Updated on: Tue, 15 September 2015 19:05]

Report message to a moderator

Re: Updating the Thing Structure [message #1708356 is a reply to message #1708352] Tue, 15 September 2015 20:32 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
The channels are linked when the thing is created (for each channel type that exists at the thing type). If you add a channel later you have to enable it manually in the Paper UI.
Re: Updating the Thing Structure [message #1708449 is a reply to message #1708356] Wed, 16 September 2015 15:19 Go to previous messageGo to next message
Haris Sibonjic is currently offline Haris SibonjicFriend
Messages: 6
Registered: April 2015
Junior Member
Hi Denis,
Thanks for fast reply. I have one small issue or problem. I checked channels in Paper UI and they are not displayed http://i.imgur.com/TuWETKw.png.

Is there any way I could call rest api to make a link, and if yes what is the api call.

[Updated on: Wed, 16 September 2015 15:23]

Report message to a moderator

Re: Updating the Thing Structure [message #1708712 is a reply to message #1708449] Sat, 19 September 2015 07:23 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
At the moment your channels don´t have a type, right? Well the Paper UI renders only channels with a type. But it can be fixed, to also show channels without a type.
Re: Updating the Thing Structure [message #1709721 is a reply to message #1708712] Wed, 30 September 2015 14:23 Go to previous messageGo to next message
Haris Sibonjic is currently offline Haris SibonjicFriend
Messages: 6
Registered: April 2015
Junior Member
Hi Denis,
Is there a way I could add/create my own channel types?

[Updated on: Wed, 30 September 2015 14:23]

Report message to a moderator

Re: Updating the Thing Structure [message #1710169 is a reply to message #1709721] Mon, 05 October 2015 07:37 Go to previous message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
Haris, yes, you can simply define them in the XML (see https://www.eclipse.org/smarthome/documentation/development/bindings/thing-definition.html#channels) and from your channels, you can then reference them by ID.
Previous Topic:Notify Status Change?
Next Topic:Supported Commands/States for A Given Item Type String in BaseThingHandler
Goto Forum:
  


Current Time: Fri Apr 19 14:29:11 GMT 2024

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

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

Back to the top