Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Identical Things provided by different ThingProviders(How to deal with this?)
Identical Things provided by different ThingProviders [message #1775582] Wed, 01 November 2017 18:13 Go to next message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
The current implementation of the ThingRegistry stores Things provided by ThingProvider on a per ThingProvider basis, which means that two ThingProviders can provide the same Thing (that is, same thing UID), and they get both stored in the the ThingRegistry

ThingManager when calling getProvider() or get() on the ThingRegistry will receive the ThingProvider of the first Provider that provides the given Thing, leaving out the other ThingProvider(s) that happen to provide that Thing

I have a situation whereby I am implementing a ThingProvider that is part of a Binding, and I want that ThingProvider to check if a Thing already exists in the ThingRegistry before deciding to provide that Thing. The reason is that want to be able to define a Thing via the DSL (and thus that is provided by the GenericThingProvider), and only extend that Thing with new Channels if it would happen to be already provided by another Provider, so that in essence, a user can define the Thing and Channels, and then have it automatically completed by the Binding. If the thing would not be present in the ThingRegistry, the binding's ThingProvider would provide it, with all the Channels and so forth.

More concrete, I would like to define Things for the KNX binding in the DSL, define Channels on those Things, but later on automatically parse KNX ETS xml files, add additional Things based on those xml files, but only define additional Channels on those Things that would be provided/defined by through the DSL beforehand.

No where in the Core checks are done on whether Things are already provided by other Providers, I think.

So, how to deal with this situation?

Should the ThingProvider bind to the ThingRegistry services, and go from there? or should it implement ThingRegistryChangeListener and keep track of Things itself?

Re: Identical Things provided by different ThingProviders [message #1775936 is a reply to message #1775582] Wed, 08 November 2017 12:20 Go to previous messageGo to next message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
The registries actually check whether a certain entity UID is already used and discards any duplicates from other providers: https://github.com/eclipse/smarthome/blob/914ce111351f8dd094af8972714c83462759b7e5/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/registry/AbstractRegistry.java#L279-L283

Quote:
I am implementing a ThingProvider that is part of a Binding


I think your issue starts right here. A binding must neither implement its own ThingProviders nor access the ThingRegistry.
The mechanism that a binding must use is that of a discovery service - this allows it to "suggest" Things and if a Thing with the same UID already exists (because it is e.g. defined in a DSL), the discovery result is automatically ignored.

Wrt extending existing Things that might be defined in a DSL: Your handler can at any time dynamically add channels to those, but it will have to do so upon every restart, if the Thing is read-only (i.e. not originating from the ManagedProvider).
Re: Identical Things provided by different ThingProviders [message #1775951 is a reply to message #1775936] Wed, 08 November 2017 14:17 Go to previous message
Karel Goderis is currently offline Karel GoderisFriend
Messages: 198
Registered: March 2014
Senior Member
Quote:
I think your issue starts right here. A binding must neither implement its own ThingProviders nor access the ThingRegistry.
The mechanism that a binding must use is that of a discovery service - this allows it to "suggest" Things and if a Thing with the same UID already exists (because it is e.g. defined in a DSL), the discovery result is automatically ignored.


[I edited my response after revisiting some old Discovery service code]

Kai, as far as I can see, DiscoveryResultBuilder and/or DiscoveryResult do not have support for Channels. One can only build the base Thing with properties, but how does one create discovery results with a custom set of Channels ?

K

[Updated on: Thu, 09 November 2017 21:12]

Report message to a moderator

Previous Topic:Questions about best practices implementing bindings
Next Topic:Items REST API - Add formatting flag
Goto Forum:
  


Current Time: Fri Apr 19 07:37:50 GMT 2024

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

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

Back to the top