Hello,
As I’m progressing on my AirZone binding, I have started implementing a discovery service and it works just fine when used with the “scan” button.
However, I am facing an issue with the background discovery overrides that I have just added.
Basically, startBackgroundDiscovery
is not called on the same instance as the one used to call startScan
and that means the first instance is never informed about the bridge handler it needs to perform its work.
I placed breakpoints in my constructors and the parameterless one is called very early in the binding life, then startBackgroundDiscovery
is called on that instance.
Then, later, when the bridge handler has been created (via createHandler
in the factory), a new instance of the discovery service is created and appears to replace the previous one.
To sum up, here is what I observed:
openHAB starts
binding gets loaded
AirZoneDiscoveryService()
is called to created instance1
instance1.startBackgroundDiscovery
is called which starts a scheduled task that will instance1.startScan
on a regular basis.
A little bit later, AirZoneHandlerFactory.createHandler()
is called which leads to AirZoneHandlerFactory.registerDeviceDiscoveryService
This method then calls AirZoneDiscoveryService(Localization)
to create instance2
instance2.addBridge
is called
When the Scan button is pressed in MainUI, it is instance2.startScan
that is called and which works properly because the bridgeHandlers
collection is not empty.
But because instance1
was never seen by the factory, the instance1.addBridge
method is never called and instance1.startScan
will exit early because of that.
I tried removing the @Component
annotation on the AirZoneDiscoveryService
class declaration and it made the first instance not being created, but startBackgroundDiscovery
is never called in that case.
I believe I have missed something to have AirZoneHandlerFactory.discoveryService
be automatically populated by instance1
but I’m at loss as to what’s missing, nothing came up from my look at other bindings.
If you want to have a look, the code is available here:
AirZoneDiscoveryService.java
AirZoneHandlerFactory.java
Note that I know it’s not in perfect shape when it comes to styling, but I’m looking at having it work first, then I’ll clean it up according to the linter rules.
Many thanks for your help.