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

Implement smarter sensor polling #188

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open

Conversation

dmulcahey
Copy link
Contributor

@dmulcahey dmulcahey commented Aug 30, 2024

This PR changes the way that polling sensors work. PollableSensor has been updated to use the GlobalUpdater and a heuristic has been added to identify when the device is reporting attributes so that it can disable the polling since it shouldn't be needed.

This accomplishes 3 things:

  1. devices that report will stop polling after the report threshold is reached (it would be good to be able to persist this across restarts)
  2. polling of non reportable devices now is limited so that only 3 devices will poll at any given time (gather with limited concurrency)
  3. less polling tasks get created (1 vs # of devices previously)

TODO: handle previously known device models so they avoid the work

Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.89%. Comparing base (57cc44b) to head (960d20d).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #188   +/-   ##
=======================================
  Coverage   95.89%   95.89%           
=======================================
  Files          61       61           
  Lines        9404     9412    +8     
=======================================
+ Hits         9018     9026    +8     
  Misses        386      386           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dmulcahey dmulcahey changed the title [RFC] Smarter sensor polling Implement smarter sensor polling Sep 7, 2024
@dmulcahey dmulcahey marked this pull request as ready for review September 7, 2024 19:45
@@ -394,34 +402,49 @@ def stop(self):
self._updater_task_handle = None
_LOGGER.debug("global updater stopped")

def register_update_listener(self, listener: Callable):
def register_update_listener(self, listener: Callable | Callable[[], Awaitable]):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if the typing is right on this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant