Skip to content
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

Merged
merged 4 commits into from
Dec 30, 2020
Merged

Conversation

mhilbush
Copy link
Contributor

Fixes #9496

@kaikreuzer Could I trouble you for a review please?

@mhilbush mhilbush added the bug An unexpected problem or unintended behavior of an add-on label Dec 25, 2020
@mhilbush mhilbush requested a review from kaikreuzer December 25, 2020 22:21
Copy link
Member

@kaikreuzer kaikreuzer left a 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()) {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

@mhilbush mhilbush Dec 27, 2020

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'.

Copy link
Member

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]>
@mhilbush
Copy link
Contributor Author

@kaikreuzer I've addressed your review comments. Thanks!!

I've also posed a question for you on some other odd behavior I was seeing.

discover();
}

private void discover() {
Copy link
Contributor

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().

Copy link
Contributor Author

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?

Signed-off-by: Mark Hilbush <[email protected]>
Copy link
Member

@kaikreuzer kaikreuzer left a 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.

@kaikreuzer kaikreuzer requested a review from cpmeister December 28, 2020 16:34
@cpmeister cpmeister added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Dec 29, 2020
@cpmeister cpmeister merged commit f9b7632 into openhab:main Dec 30, 2020
@cpmeister cpmeister added this to the 3.1 milestone Dec 30, 2020
@mhilbush mhilbush deleted the ecobee-rework-discovery branch December 30, 2020 13:36
thinkingstone pushed a commit to thinkingstone/openhab-addons that referenced this pull request Nov 7, 2021
* Rework discovery
* Consolidate discovery into one service

Signed-off-by: Mark Hilbush <[email protected]>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
* Rework discovery
* Consolidate discovery into one service

Signed-off-by: Mark Hilbush <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Ecobee] Thread issues with discovery services
3 participants