-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
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
Make rest sensor and binary sensor more efficient #14484
Make rest sensor and binary sensor more efficient #14484
Conversation
|
||
if rest.data is None: | ||
_LOGGER.error("Unable to fetch REST data from %s", resource) | ||
return False |
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.
We should raise PlatformNotReady
. Keep in mind that the platform can't recover if the credentials or header entries are wrong. Then the users will end-up with non-functional platforms in their setup.
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 for the review - I see what you mean.
I am hoping to find a way to distinguish between recoverable and unrecoverable errors. Once the sensor is correctly set up (correct URL, correct username/password, etc.), it would be nice if the code could handle intermittent errors. At present, if a third-party service used in a rest binary sensor is unavailable just at the time when HA is restarted, that binary sensor is not created.
BTW: A rest sensor is still created in the same situation. And a rest switch is only not created if the HTTP response code is >= 400 or if specific exceptions occur; this may be a role model for sensor and binary sensor?
I'll look into PlatformNotReady
.
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.
Alright, I wasn't aware that when raising a PlatformNotReady
HA automatically retries after 30 seconds (with backoff). That definitely helps with intermittent errors during the setup of the sensors.
@fabaff: As suggested I changed the setup of the sensors to raise |
You could set this parameter to false: To avoid the first update call. |
@syssi: That approach would work for the rest binary sensor. However, if the rest sensor isn't updated immediately it remains in an unknown state(i.e. |
Are there any more suggestions on how to improve this PR or can it be merged please? |
The problem of throttling the update method is you cannot use a SCAN_INTERVAL < 10 seconds anymore. :-( |
Yes, that is correct. |
…en through add_devices
…l rest call fails; throttling the update to avoid fetching the same resource again immediately after setting up sensor
…ing the binary sensor's rest resoure twice; fixed tests
157d2b1
to
5fa8175
Compare
@syssi: Is this now ready to be merged? |
Is there anything left to do for this PR, or can this be merged now? |
Description:
I am proposing the following small changes to the rest sensor and rest binary sensor:
add_devices
call.I propose to initially only make one call to fetch the rest resource.For the binary sensor I propose to initially only make one call to fetch the rest resource - the sensor state can be determined based on that.Related issue (if applicable): n/a
Pull request in home-assistant.github.io with documentation (if applicable): n/a
Example entry for
configuration.yaml
(if applicable):n/a
Checklist:
tox
. Your PR cannot be merged unless tests pass