Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Thing / Channel Configuration Question
Thing / Channel Configuration Question [message #1687711] Thu, 19 March 2015 19:19 Go to next message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
Hi,

Let's assume I have channel which implements a switch. Something like:

<channel-type id="state">
<item-type>Switch</item-type>
<label>Switch</label>
<description>Turns the power on or off</description>
<category>Switch</category>
</channel-type>

If for example I have a property in the physical device which I can set, e.g. let's assume that I can add a delay before I turn the power on.

My question is, how do I add this delay property? Should be added as a new channel?

I see it more as a configuration of the device but I am not sure if adding configuration to the channel is the right approach. If I add it as a configuration, how do the thing handle knows about the change of the configuration?

Thx
Re: Thing / Channel Configuration Question [message #1688358 is a reply to message #1687711] Fri, 20 March 2015 14:29 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
Hi Eyal,

I see actually two different options here:
1. This is a property which you have to set in the device and which makes its functionality behave in a certain way (when receiving "ON", it always reacts with a delay of x seconds). For this, the Channel itself holds a "Configuration" object that can be used. Having said this, there is indeed no support of this feature in the framework yet, so there are no easy ways to change this configuration and to be notified about updates. So the easier solution for now might be to put the configuration property directly on the thing and not on the channel.
2. The property is not a "one-for-all", but you could e.g. have one item linked to the channel with a 2 second delay and another item with a 5 second delay. In this case, it should not be considered as a configuration of the channel itself, but of the item-channel-link. There is a bugzilla feature request for such a functionality already: https://bugs.eclipse.org/bugs/show_bug.cgi?id=456213

Best regards,
Kai
Re: Thing / Channel Configuration Question [message #1692202 is a reply to message #1688358] Tue, 14 April 2015 10:03 Go to previous messageGo to next message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
Hi Kai,

As far as I understand, I can notify the framework from the binding on configuration change by calling: updateConfiguration.

How do I notify the binding from the framework on configuration change?

Thx
Re: Thing / Channel Configuration Question [message #1692279 is a reply to message #1692202] Tue, 14 April 2015 17:22 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Hi Eyal,

maybe this documentation helps you: https://github.com/eclipse/smarthome/blob/master/docs/sources/architecture/thing-handler.md#handling-thing-updates .

The configuration is part of the thing. So there is a method "thingUpdated", which is automatically called by the framework, if the configuration is changed in the UI for example. But you need to figure out manually, which property was changed.

Regards

Dennis
Re: Thing / Channel Configuration Question [message #1692530 is a reply to message #1692279] Thu, 16 April 2015 11:07 Go to previous messageGo to next message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
Thx, I will check it.

But I still have the issue how to update channel configuration of binding from the framework.

I thought of adding a new command, something like "UpdateType" that will be send to the binding from the framework when the channel configuration has been changed by the user. This is somehow identical to the refresh type command that is sent.

Do you think it is a "valid" solution until there will be in the future support for configuration update?

Thx
Eyal
Re: Thing / Channel Configuration Question [message #1692608 is a reply to message #1692530] Thu, 16 April 2015 20:06 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Theoretically (which means I did not test it) the "thingUpdated" method should also be called if the configuration of a channel was changed. Does it not work?

I don´t think that it makes sense to introduce a command for informing about updates, because commands tell the binding something it should do, like "turn the Switch ON". But they are not meant to inform the binding about something, which happened in the framework. The RefreshType tells the binding to force a state refresh.

We may rethink the concept of configuration update notifications to have separate methods like "thingConfigurationUpdated()" and "channelConfigurationUpdated(ChannelUID channelUID)".

Regards

Dennis

[Updated on: Thu, 16 April 2015 20:16]

Report message to a moderator

Re: Thing / Channel Configuration Question [message #1692610 is a reply to message #1692608] Thu, 16 April 2015 20:30 Go to previous messageGo to next message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
Hi Dennis,

Agree to all.

I also think that update command is not the right solution but I thought of adding it as a workaround until hopefully you will introduce solution.

I still didn't check the thingUpdate and I will do it.

Eyal
Re: Thing / Channel Configuration Question [message #1692685 is a reply to message #1692608] Fri, 17 April 2015 10:56 Go to previous messageGo to next message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
Dennis,

Should I call editConfiguration and than updateConfiguration from the thing handler?

It is not clear to me if this is the right way to update the thing. The documentation says: "Informs the framework, that the given configuration of the thing was updated." and I understand it as updating the framework and not the actual thing so it is little confusing.

Help will be appreciated.

Thx
Eyal
Re: Thing / Channel Configuration Question [message #1692756 is a reply to message #1692685] Fri, 17 April 2015 14:58 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
We have to scenarios:

1) User changes configuration in the UI -> Binding will be informed with "thingUpdated" about the changed configuration parameters
2) Binding recognizes configuration change (maybe from an external app) -> Binding has to inform the framework via "updateThing" about configuration changes, so that UI can reflect it

Which case do you want to support?

Regards

Dennis
Re: Thing / Channel Configuration Question [message #1693062 is a reply to message #1692756] Tue, 21 April 2015 13:43 Go to previous messageGo to next message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
I want first to support the first scenario: User changes configuration in the UI

Thx!!!
Re: Thing / Channel Configuration Question [message #1693753 is a reply to message #1692756] Tue, 28 April 2015 07:11 Go to previous messageGo to next message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
Actually I support both. Updating the thing from the binding can be done via the BaseThingHandler :

/**
* Informs the framework, that a thing was updated. This method must be called after the configuration or channels
* was changed.
* /
protected void updateThing(Thing thing)

/**
* Informs the framework, that the given configuration of the thing was updated.
* /
protected void updateConfiguration(Configuration configuration)


(BTW, it is not clear to me if I need to call update thing after update configuration.).

My main problem is that I don't see any way to update the binding from the UI (Note that I am using custom UI).

Thx

Re: Thing / Channel Configuration Question [message #1693760 is a reply to message #1693753] Tue, 28 April 2015 08:14 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
> (BTW, it is not clear to me if I need to call update thing after update configuration.).

You don´t have to. It is a connivence method, that internally calls updateThing for you. Maybe we should clarify that in the documentation.

> My main problem is that I don't see any way to update the binding from the UI (Note that I am using custom UI).

Is it a UI you are developing? Then you can use the REST resource "rest/things" for showing the current configuration of things and "PUT rest/things/{thingUID}" for updating it.
Re: Thing / Channel Configuration Question [message #1693764 is a reply to message #1693760] Tue, 28 April 2015 08:55 Go to previous messageGo to next message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
I am building an application which is based on the core of the SmartHome eclipse. UI is part of it. Currently I don't use REST. I call the core directly and I cannot find a way to update the binding when thing configuration has changed by user Sad

Actually, the problem is bigger because I also cannot find a way to update the channel configuration ...

Is there a way to do it withing the core itself?
Re: Thing / Channel Configuration Question [message #1693788 is a reply to message #1693764] Tue, 28 April 2015 11:30 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Yes for sure. You can use the ThingRegistry and call updateThing. This will trigger the thingUpdated() callback in the binding. It is the same what the REST resource is doing internally.
Re: Thing / Channel Configuration Question [message #1693849 is a reply to message #1693788] Tue, 28 April 2015 17:59 Go to previous messageGo to next message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
So now I get the thingUpdate. Some progress Smile.

My issue is that I only updated the thing / channel configuration and the result will be that dispose and initialize will be called.

I can override this in the binding handler and not call the super. Is this is what should be done? Why the dispose and initialize is in the base?

My next step is to understand how to identify what was change ...

Thx for your continues help!

@Override
public void thingUpdated(Thing thing) {
dispose();
this.thing = thing;
initialize();
}
Re: Thing / Channel Configuration Question [message #1693856 is a reply to message #1693849] Tue, 28 April 2015 19:50 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Quote:
My issue is that I only updated the thing / channel configuration and the result will be that dispose and initialize will be called.

I can override this in the binding handler and not call the super. Is this is what should be done? Why the dispose and initialize is in the base?


Yes this is what should be done. This is an excerpt of the documentation: "If your binding contains resource-intensive logic in your initialize method, you should think of implementing the method by yourself and figuring out, what is the best way to handle the change." (see https://github.com/eclipse/smarthome/blob/master/docs/sources/architecture/thing-handler.md#handling-thing-updates). Please also see the other topic were thingUpdated was discussed: https://www.eclipse.org/forums/index.php/t/1065989/.

Quote:
My next step is to understand how to identify what was change


Unfortunately this is a current limitation (as I wrote before: https://www.eclipse.org/forums/index.php?t=msg&th=1063144&goto=1692279&#msg_1692279).

[Updated on: Tue, 28 April 2015 19:52]

Report message to a moderator

Re: Thing / Channel Configuration Question [message #1693960 is a reply to message #1693856] Wed, 29 April 2015 14:09 Go to previous message
Smart Home is currently offline Smart HomeFriend
Messages: 109
Registered: February 2015
Senior Member
Dennis,

I thought that after the update of the thing (or one of its channels) I will get the old thing and the modified thing and than I will be able to compare them to find what were the changes.

But, I don't see how I get the old thing before the configuration change. What is wrong in the sequence?

1. I get the configuration of a thing in my application with:

Configuration configuration = thing.getConfiguration();

2. I perform changes to the configuration.

3. I call update via the registry:

thingRegistry.update(thing);

4. Thing registry notify on Update

@Override
protected void notifyListenersAboutUpdatedElement(Thing oldElement, Thing element) {
super.notifyListenersAboutUpdatedElement(oldElement, element);
notifyTrackers(element, ThingTrackerEvent.THING_UPDATED);
}

5. Thing manager gets the update via the tracker

@Override
public void thingUpdated(Thing thing, ThingTrackerEvent thingTrackerEvent) {


6. Thing handler is being notified

thingHandler.thingUpdated(thing);

And here is the problem: I gets the thing with the changes but I don't have reference to the thing before the changes.

Previous Topic:Can Handlers disappear?
Next Topic:Can not updateStatus() in bridgeHandlerInitialized()
Goto Forum:
  


Current Time: Tue May 14 20:24:56 GMT 2024

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

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

Back to the top