Repository navigation
Simplify the ping sweep after the sweep-base and public-seam refactors - #2046
Conversation
|
ESPHome Bot (@esphbot) review |
Merging this PR will not alter performance
Comparing Footnotes
|
|
|
There was a problem hiding this comment.
Pull request overview
Refactors the device-state monitor’s ping sweep implementation after the SweepSource/base-loop and public-seam changes, aiming to keep behavior unchanged aside from improved logging and consolidated predicates.
Changes:
- Moves
wake()ontoSweepSourceand updates callers to use the shared wake mechanism. - Consolidates “no target” and “ping OFFLINE” spellings via
shared.sweep_has_no_target()andshared.apply_ping_result(). - Adds
helpers.async_.log_gather_failures()and uses it to loggather(..., return_exceptions=True)failures consistently (including in the ping pass and mDNS pre-resolve), plus simplifies zeroconf shutdown draining.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_state_monitor_lifecycle.py | Adjusts the flicker-driver to reflect the updated cheapest-first target predicate. |
| tests/test_api_reviver.py | Updates the ICMP availability test to match the new boolean icmp_available contract. |
| esphome_device_builder/helpers/async_.py | Adds log_gather_failures() helper to standardize gather-result triage/logging. |
| esphome_device_builder/controllers/_device_state_monitor/shared.py | Replaces address_resolution_exhausted with sweep_has_no_target and folds in the RAM-addresses gate. |
| esphome_device_builder/controllers/_device_state_monitor/ping.py | Uses log_gather_failures, routes OFFLINE transitions through apply_ping_result, and moves ping_once into the public section. |
| esphome_device_builder/controllers/_device_state_monitor/mdns.py | Simplifies interface-monitor shutdown by using drain_tasks(log_exceptions=True). |
| esphome_device_builder/controllers/_device_state_monitor/api_reviver.py | Updates cohort gating and docs to use sweep_has_no_target and boolean icmp_available. |
| esphome_device_builder/controllers/_device_state_monitor/api_info.py | Uses self.wake() instead of directly setting _wake. |
| esphome_device_builder/controllers/_device_state_monitor/_sweep_source.py | Adds SweepSource.wake() as shared base machinery for sweep sources. |
|
ESPHome Bot (@esphbot) review |
ee7dafc to
a7f0da7
Compare
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
|
ESPHome Bot (@esphbot) review |
PR Review — Simplify the ping sweep after the sweep-base and public-seam refactorsClean, behavior-preserving refactor. Merge-ready. Verified strengths:
Checklist
Automated review by Kōan (Claude) |
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2046 +/- ##
=======================================
Coverage 99.60% 99.60%
=======================================
Files 243 243
Lines 19718 19725 +7
=======================================
+ Hits 19641 19648 +7
Misses 77 77
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
What does this implement/fix?
Cleanup pass over the ping sweep following the sweep-base adoption (#2035) and the public-seam rename (#2037). Behavior-free apart from log lines:
wake()moves ontoSweepSource; it was base machinery stranded onPingSourceafter Rehome the sweep-loop base and adopt it in PingSource #2035, andApiInfoSource.request_reprobewas re-spellingself._wake.set()inline.monitor.apply(name, OFFLINE, "ping")calls (no-target selection, resolve-empty) now route throughshared.apply_ping_result(monitor, name, None)like the probe path and the reviver, so the ping-sourced transition has one spelling.helpers.async_.log_gather_failuresowns the gather triage (log failures, re-raise cancellations)._sweep's hand-rolled isinstance loop uses it, and the_ping_sweepgather, which previously discarded exceptions silently, now logs them.mdns.close_zeroconf's hand-rolled single-task drain becomesdrain_tasks(log_exceptions=True).shared.address_resolution_exhaustedbecomesshared.sweep_has_no_target(monitor, device), folding in thenot runtime_state.ip_addressesconjunct both call sites (ping selection, reviver cohort gate) were adding by hand; the "keep in lockstep" contract now lives in one predicate. Checks run cheapest-first, so the zeroconf cache walk only pays off after a proven DNS failure.icmp_availablede-tri-states to a plain bool; its only consumer (the reviver's_prepare) never distinguishedNonefromFalse.ping_oncemoved into the public section beside the other cross-source seams.The flicker log test needed its driver fixed: the cheap-first predicate no longer consults the DNS-failure cache once RAM addresses exist, so the test's flaky device now genuinely never resolves, making the bucket flicker real instead of an artifact of call counting.
Out-of-scope efficiency findings from the same review (the per-device
has_live_ptrfull-bucket scan, per-sweep fleet snapshot reuse, bounded ping workers) are tracked in a separate issue.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.