Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Event driven binding - Implementation pattern advice
Event driven binding - Implementation pattern advice [message #1769909] Sat, 05 August 2017 09:29 Go to next message
Jabba Loon is currently offline Jabba LoonFriend
Messages: 11
Registered: August 2017
Junior Member
Hi All,

Am mid-way through creation of my first binding for an Alarm panel. As with most panels, the panel has to be polled for updates. However, I have previously created a framework/model to abstract the panel an produce events when things happen.

For example, my existing framework/model runs away on its own thread and can fire an event when say a zone status (open/closed) changes.

What I am trying to figure out is the best way to translate that event into an item state update for the relevant 'thing'.

For example, I believe that I could give a reference to my bridge handler to my existing event handler and have that event handler iterate over all 'things' to see if any of their states need to be updated based on a given alarm event that has occurred, eg:

List<Thing> things = getThing().getThings();
...
...

However, this doesn't feel right or efficient! So before I go any further, I wanted to get some input from you guys to make sure I do it the 'right' way!

Any thoughts / comments appreciated.
Cheers
Re: Event driven binding - Implementation pattern advice [message #1770002 is a reply to message #1769909] Mon, 07 August 2017 12:45 Go to previous messageGo to next message
Jabba Loon is currently offline Jabba LoonFriend
Messages: 11
Registered: August 2017
Junior Member
For what its worth, I have implemented a solution whereby then bridge handler implements an interface to enable it to become a consumer of events from the existing notification framework. When an event is notified, the bridge iterates through the list of things it has, eg List<Thing> things = getThing().getThings(); to find the thing that the event pertains to. Then, when found, finds the relevant channel and does an updateState().

Everything works as expected and all is good. However, if anyone has an comments or suggestions in relation to the best/most efficient (etc...) approach, would appreciate hearing them. Am learning as I go and want to make sure that I am doing things (pardon the pun!) in the most correct way.

Cheers
Re: Event driven binding - Implementation pattern advice [message #1770050 is a reply to message #1770002] Mon, 07 August 2017 18:23 Go to previous messageGo to next message
Dan Cunningham is currently offline Dan CunninghamFriend
Messages: 44
Registered: March 2014
Member
Hi, are you using any other bindings as an example? There a lots of them that have to poll and are probably a similar use case to yours.

In regards to a separate thread for polling, the BaseThingHandler provides a ScheduledExecutorService for just this purpose, the idea is that threads are handled as much as possible in ESH. Sometimes bindings do need their own threads , but if your use case is simple polling, this might be better.
Re: Event driven binding - Implementation pattern advice [message #1770055 is a reply to message #1770050] Mon, 07 August 2017 19:36 Go to previous messageGo to next message
Jabba Loon is currently offline Jabba LoonFriend
Messages: 11
Registered: August 2017
Junior Member
Thanks Dan. Yes, am looking at lots of different binding implementations for guidance. The problem (and I guess the source of the question) is that there seems to be plenty of different ways of doing it. By the sounds of it, what I have done seems to be reasonable / ok. thanks Jabba
Re: Event driven binding - Implementation pattern advice [message #1770260 is a reply to message #1770055] Wed, 09 August 2017 12:58 Go to previous messageGo to next message
Stefan Triller is currently offline Stefan TrillerFriend
Messages: 29
Registered: April 2017
Junior Member
Hi Jabba,

I agree, iterating over the
List<Thing> things = getThing().getThings()
is certainly not efficient. How do you "find" your right thing in your current setup?

A better way to do it is is to add properties to your things: https://eclipse.org/smarthome/documentation/development/bindings/thing-definition.html#properties

With these properties you could make them identifiable. Inside your BridgeHandler you can then override
childHandlerInitialized(ThingHandler childHandler, Thing childThing)
to be notified about a new thing and add it to a Map<YOUR_IDENTIFIER, Thing>.

Regards,

Stefan
Re: Event driven binding - Implementation pattern advice [message #1772432 is a reply to message #1770260] Sat, 09 September 2017 15:06 Go to previous message
Jabba Loon is currently offline Jabba LoonFriend
Messages: 11
Registered: August 2017
Junior Member
Thanks Stefan, that makes sense. Will implement that way.

Cheers,
Jabba
Previous Topic:Dynamically changing item-type category during discovery
Next Topic:Need help with understanding Architecture
Goto Forum:
  


Current Time: Fri Apr 19 05:04:38 GMT 2024

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

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

Back to the top