Repository navigation
Rehome the sweep-loop base and adopt it in PingSource - #2035
Conversation
|
ESPHome Bot (@esphbot) review |
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2035 +/- ##
==========================================
- Coverage 99.60% 99.60% -0.01%
==========================================
Files 242 243 +1
Lines 19745 19740 -5
==========================================
- Hits 19667 19662 -5
Misses 78 78
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the device-state monitor’s “presence-gated fixed-interval sweep loop” into a shared SweepSource base, then adopts it in PingSource (and re-threads the Native API sources through an ApiSweepSource subclass) to remove duplicated loop plumbing and unify behavior like crash-continue.
Changes:
- Introduce
SweepSourceas the shared presence-gated sweep-loop template, and adapt API probe plumbing to layer on top of it. - Migrate
PingSourceto inherit fromSweepSource, moving interval/bootstrap timing to class attributes and keeping ping-specific sweep behavior intact. - Update/extend tests to patch the new class attributes and to pin the “sweep crash doesn’t kill the loop” behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_subscriber_presence.py | Updates documentation wording to reference the generic sweep interval contract. |
| tests/test_state_monitor_lifecycle.py | Updates ping loop interval/bootstrap monkeypatching to target PingSource class attrs; adjusts wording around interval. |
| tests/test_probe_device_ping.py | Updates ping loop interval/bootstrap monkeypatching to target PingSource class attrs; tweaks docstring wording. |
| tests/test_ping_loop_pause.py | Switches monkeypatching from module constants to PingSource class attrs and adds a test pinning crash-continue behavior. |
| tests/test_api_reviver.py | Updates reviver _prepare tests for async _prepare() after the sweep base change. |
| tests/test_api_info_fallback.py | Switches interval patching to ApiInfoSource._interval and validates SweepSource base behavior. |
| tests/conftest.py | Updates fixture docstring to reflect ICMP privilege probe moving into PingSource._prepare. |
| esphome_device_builder/controllers/_device_state_monitor/shared.py | Updates comment wording to reference “sweep interval” rather than ping-specific constants. |
| esphome_device_builder/controllers/_device_state_monitor/ping.py | Migrates PingSource onto SweepSource, moving bootstrap/interval to base attrs and keeping ping-specific sweep logic. |
| esphome_device_builder/controllers/_device_state_monitor/api_reviver.py | Makes _prepare async to match the new sweep base contract. |
| esphome_device_builder/controllers/_device_state_monitor/api_info.py | Makes _prepare async to match the new sweep base contract. |
| esphome_device_builder/controllers/_device_state_monitor/_sweep_source.py | Adds the shared sweep-loop base (SweepSource) with presence gating, crash-continue, and idle-wake behavior. |
| esphome_device_builder/controllers/_device_state_monitor/_api_probe.py | Rehomes the sweep-loop base dependency and narrows _api_probe.py to API worker-dial plumbing via ApiSweepSource(SweepSource). |
|
ESPHome Bot (@esphbot) review |
PR Review — Rehome the sweep-loop base and adopt it in PingSourceClean, well-tested behavior-preserving refactor; extracts a neutral Strengths:
Needs attention (nits only):
🟢 Suggestions
1. Consider safe defaults for `_sweep_label` / `_bootstrap_delay`
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
What does this implement/fix?
PR #2014 extracted the presence gated sweep loop into
_api_probe.py, whereApiInfoSourceandApiReviverSourcerun on it whilePingSourcestill hand rolled the identical loop. This moves the loop base to a neutral_sweep_source.py(SweepSource), keeps the budgeted worker dial and its_run_workertest seam in_api_probe.pyas a thinApiSweepSource(SweepSource)layer, and migratesPingSourceonto the base. The privilege probe made_prepareasync on the base; ping's resolve gather step keeps its bespoke exception handling inside its_sweep. Interval and bootstrap delay are now class attrs on the base, so the ping test seams patchPingSource._bootstrap_delay/_intervallike the API sources already did.One behavior change worth naming: the ping sweep body now gets the template's crash continue, so a raising
_ping_sweeplogs and retries next interval instead of killing the loop task for the process lifetime; a new test pins it. Cancellation still propagates.Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesFrontend coordination
Checklist
ruff,codespell, yaml/json/python checks).tests/where applicable.components.index.json/definitions/components/*.jsonhave not been hand-edited (regenerate viascript/sync_components.pyif a sync is needed).docs/ARCHITECTURE.mdand/ordocs/API.md.