-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ecobee] Rework discovery #9522
Conversation
Signed-off-by: Mark Hilbush <[email protected]>
Signed-off-by: Mark Hilbush <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mhilbush, looks pretty good to me!
Just 2 small comments below.
} | ||
|
||
private void discover() { | ||
if (!bridgeHandler.isBackgroundDiscoveryEnabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should be removed. This method is called upon manually triggered scans, so it must be performed even if background discovery is not activated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I'll fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
logger.debug("EcobeeDiscovery: Starting background discovery job"); | ||
Future<?> localDiscoveryJob = discoveryJob; | ||
if (localDiscoveryJob == null || localDiscoveryJob.isCancelled()) { | ||
discoveryJob = scheduler.scheduleWithFixedDelay(this::discover, DISCOVERY_INITIAL_DELAY_SECONDS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should check whether isBackgroundDiscoveryEnabled
returns true before scheduling this job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can see, startBackgroundDiscovery
is being called before the bridge handler has initialized, therefore the configuration is not available at the time the job is scheduled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I see. Then keep the scheduled job active in any case and do the check within the job as you intended to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought it was odd that startBackgroundDiscovery
can be called before the bridge thing has initialized. Especially in the case where the discovery service implements ThingHandlerService
in order to get access to the bridge handler.
I also ran into something a little weird for which I'd like your opinion. Let me know if you think I should log an issue for this.
Here's the scenario:
I have a things file containing two bridge things:
Bridge ecobee:account:account "Ecobee Account" [ apiKey="XXXXXXX", apiTimeout=20, discoveryEnabled=false, refreshIntervalNormal=30, refreshIntervalQuick=5 ] {
}
Bridge zoneminder:server:server "Zoneminder Server" [ host="zoneminder.host", useSSL=false, portNumber="80", urlPath="/zm", discoveryEnabled=false, refreshInterval=30, defaultAlarmDuration=180 ] {
}
Notice that both Bridge definitions have a parameter called discoveryEnabled
and that both are false.
If I change just the Zoneminder discoveryEnabled
to true, I see this behavior.
2020-12-27 13:15:07.103 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'test.things'
2020-12-27 13:15:07.120 [DEBUG] [.thing.internal.GenericThingProvider] - Read things from model 'test.things'
2020-12-27 13:15:07.122 [DEBUG] [.thing.internal.GenericThingProvider] - Updating thing 'ecobee:account:account' from model 'test.things'.
2020-12-27 13:15:07.136 [DEBUG] [.thing.internal.GenericThingProvider] - Updating thing 'zoneminder:server:server' from model 'test.things'.
If I change just the Zoneminder discoveryEnabled
back to false, I see this behavior.
2020-12-27 13:17:36.865 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'test.things'
2020-12-27 13:17:36.883 [DEBUG] [.thing.internal.GenericThingProvider] - Read things from model 'test.things'
2020-12-27 13:17:36.886 [DEBUG] [.thing.internal.GenericThingProvider] - Updating thing 'ecobee:account:account' from model 'test.things'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds not what one would expect. Clearly, the thing where something has changed should be updated...
If you are able to minimise this to an easily reproducible case (without requiring any hardware, so the astro binding might be a good fit), an issue in openhab-core will make sense.
Signed-off-by: Mark Hilbush <[email protected]>
@kaikreuzer I've addressed your review comments. Thanks!! I've also posed a question for you on some other odd behavior I was seeing. |
...obee/src/main/java/org/openhab/binding/ecobee/internal/discovery/EcobeeDiscoveryService.java
Outdated
Show resolved
Hide resolved
discover(); | ||
} | ||
|
||
private void discover() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be synchronized instead of discoverThermostats()
and discoverSensors()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that. As the thermostat and sensor discovery processes are largely independent, I decided to do it at that level. Is there a preference for doing it here instead?
...src/main/java/org/openhab/binding/ecobee/internal/handler/EcobeeThermostatBridgeHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Mark Hilbush <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
@cpmeister As you commented as well, please feel free to merge when you are fine with it.
* Rework discovery * Consolidate discovery into one service Signed-off-by: Mark Hilbush <[email protected]>
* Rework discovery * Consolidate discovery into one service Signed-off-by: Mark Hilbush <[email protected]>
Fixes #9496
@kaikreuzer Could I trouble you for a review please?