Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Design question: searching for things (getThingByUID)
Design question: searching for things (getThingByUID) [message #1768281] Sun, 16 July 2017 20:20 Go to next message
Massi Ti is currently offline Massi TiFriend
Messages: 3
Registered: June 2017
Junior Member
Hallo,
In the new binding I am writing for OH2, devices are identified as:
     mybinding:deviceType:bridgeID:deviceID

where deviceID is the unique ID used to identify devices in the network protocol I am integrating, while deviceType is set during Thing discovery phase.

Then when a new device event arrives from the network protocol I need to associate the event to the Thing/ThingHandler, so I need to use getThingByUID() in the bridge handler.
However, I cannot search for the Thing as the network protocol event does not bring any info on the device type, only the deviceID.
So I cannot associate network protocol events coming from a specific deviceID with the corresponding Thing in ESH.

What is the right design approach to be used?

OPTIONS:
1) I could avoid using deviceType in the ThingUID:
     mybinding:bridgeID:deviceID

but this way the UI/user will miss the info that this device is of that specific deviceType.

2) Another option would be to have a more flexible method getThingByUID capable of finding Things also with "*" search, for example:
getThingByUID("mybinding:*:bridgeID:deviceID")

to find the Thing with ID=deviceID, regardless of its specific type.

Any other suggestion?

Thanks a lot,
Massi
Re: Design question: searching for things (getThingByUID) [message #1768387 is a reply to message #1768281] Tue, 18 July 2017 08:49 Go to previous messageGo to next message
Stefan Triller is currently offline Stefan TrillerFriend
Messages: 29
Registered: April 2017
Junior Member
Hello Massi,

I think there is a misunderstanding from you regarding the "Discovery Service". This service is completely unrelated to any "ThingManager" or the "ThingRegistry".

Massi Ti wrote on Sun, 16 July 2017 20:20

Then when a new device event arrives from the network protocol I need to associate the event to the Thing/ThingHandler, so I need to use getThingByUID() in the bridge handler.


You do not need to relate the newly discovered device to any existing "thing". This is not the job of the discovery service. The only job of the discovery service is to find the device and give it a unique identifier. Where "unique" means that if this discovery service finds the same physical device it will generate the very same unique identifier.

Saying that its perfectly fine to create a "DiscoveryResult with a unique identifier that looks like
mybinding::bridgeID:deviceID


A user can later choose to rename its things anyway.

I hope that clarifies things for you.

Regards,

Stefan
Re: Design question: searching for things (getThingByUID) [message #1768448 is a reply to message #1768387] Tue, 18 July 2017 20:35 Go to previous messageGo to next message
Massi Ti is currently offline Massi TiFriend
Messages: 3
Registered: June 2017
Junior Member
Thanks Stefan for your kind response!

I think however my question/request for help has been slightly misunderstood.
I try to re-formulate it with an example:

1) discovery starts for mybinding > bridge sends discovery request to the network protocol (serial port is used)

2) network protocol answers with list of devices > a new device is discovered and identified > DiscoveryResponse is created with
ThingUID=mybinding:deviceType:bridgeID:deviceID
(note that the network protocol discovery response contains both deviceID and deviceType of the new device)

3) user adds the new discovered thing from inbox > new thing is created with ThingUID=mybinding:deviceType:bridgeID:deviceID

4) discovery is finished > we go now in regular operation.
Bridge is the listening for network protocol events

5) a new event for deviceID is notified from network to bridge. Its a light change event: the network protocol's message only contains deviceID and the new light status (and NOT deviceType).

6) bridge wants to change thing's state (light=on) according to received event so the bridge needs to call:
getThingByUID(mybinding:deviceType:bridgeID:deviceID)
but unfortunately deviceType is not known at this point to the bridge, only deviceID is known.
So the bridge cannot obtain from ThingRegistry the corresponding thing associated to this network event.

How would you implement the
bridge protocol event -> ThingUID
mapping in this case where thing type is only known/visible at device discovery time?
My one suggestion was to have a more flexible getThingByUID method where a "wildcard" UID could be used as search criteria
(i.e. getThingByUID(mybinding:*:bridgeID:deviceID) = "Find the thing that has this deviceID on this bridgeID regardless of deviceType")

Any other design idea?

Thanks
Massi
Re: Design question: searching for things (getThingByUID) [message #1768512 is a reply to message #1768448] Wed, 19 July 2017 15:19 Go to previous messageGo to next message
Stefan Triller is currently offline Stefan TrillerFriend
Messages: 29
Registered: April 2017
Junior Member
Hello Massi,

I think I have understood your problem now. So let me briefly recap it:

Your ESH instance has a thing with ThingUID=mybinding:deviceType:bridgeID:deviceID that was previously discovered.

Now the network that your binding is connected to receives and event for "deviceID" and you want to find the corresponding thing for it, right?

The problem with that is you are making the assumption that the ThingUID contains the deviceID, but that is not necessarily the case if a user has created that thing manually via a ".things" file. then its name could simply be "myFancyThing".

So what you need is a "config-description" on your thing-type similar to
https://github.com/eclipse/smarthome/blob/master/extensions/binding/org.eclipse.smarthome.binding.hue/ESH-INF/thing/OnOffLight.xml#L21
In this configuration you should have a "parameter", probably something like "deviceID" which should be set to "required".

This "config-description" parameter has to be set by your discovery service or by someone defining a thing via a ".thing" file.

I do not know if your bridgehandler is handling the connection to the network or your thing handlers, but lets assume the bridgehandler holds the connection in some "ConnectionClient". Your thing handlers should then register themselves on that "ConnectionClient" so they receive events. They can do that together with the deviceID of their thing.

Then you have the option to hold a map of "deviceID -> thing handler" in that ConnectionClient. Once you receive an event from the network you can hand this over to the correct handler.

Inside your thing handler you can then set the status of the thing via "updateStatus".

If you have any further questions, feel free to ask.

Kind Regards,

Stefan
Re: Design question: searching for things (getThingByUID) [message #1773804 is a reply to message #1768512] Wed, 04 October 2017 20:07 Go to previous message
Massi Ti is currently offline Massi TiFriend
Messages: 3
Registered: June 2017
Junior Member
Thanks Stefan, I implemented the suggested behaviour and it works.
While I was coding, I was thinking that since this "deviceID -> thing handler" mapping is possibly common to many bindings, it should be already supported by the ESH core.
In addition I see that there is a 'representation-property' that I probably should use to make sure the same device is not discovered twice.
Is this the expected usage of this type of properties?
thanks
Massi
Previous Topic:Changing readonly at runtime
Next Topic:DiscoveryService registered but startScan not executed
Goto Forum:
  


Current Time: Thu Apr 18 07:24:56 GMT 2024

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

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

Back to the top