Repository navigation
Expose DeviceStateMonitor sources as public seams and drop the PLR0904 grandfather - #2037
Conversation
|
ESPHome Bot (@esphbot) review |
|
|
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 #2037 +/- ##
==========================================
- Coverage 99.60% 99.60% -0.01%
==========================================
Files 243 243
Lines 19739 19716 -23
==========================================
- Hits 19661 19638 -23
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
Refactors DeviceStateMonitor to expose its per-signal sources (mdns, ping, importable, api_info, api_reviver) as public seams, removing the need for sibling modules to reach into _-prefixed internals and allowing the PLR0904 grandfather to be dropped without changing runtime behavior.
Changes:
- Promote the monitor’s internal sources to public attributes and reroute cross-module access through those seams.
- Remove thin monitor-level delegators (e.g., mDNS refresh/cache reads, importable probing, version reprobe) and update production callers accordingly.
- Update/reshape tests and fakes to mirror the new public surface (
RecordingStateMonitornow provides nested typed source fakes).
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_state_monitor_reachability.py | Updates test wiring and call sites to use monitor.mdns/monitor.ping/monitor.importable. |
| tests/test_state_monitor_lifecycle.py | Adjusts lifecycle tests to the new public source attributes. |
| tests/test_probe_device.py | Switches probing tests to route through monitor.importable / monitor.mdns. |
| tests/test_probe_device_ping.py | Updates ping-loop/task spawning assertions to use monitor.ping. |
| tests/test_ping_loop_pause.py | Rewires ping pause/resume tests to the monitor.ping public seam. |
| tests/test_non_api_mdns_resolve.py | Updates non-API resolve tests to use monitor.mdns._zeroconf. |
| tests/test_mdns_resolve_first.py | Migrates sweep tests from monitor._mdns/delegators to monitor.mdns. |
| tests/test_mdns_name_match.py | Updates mDNS start call to use monitor.mdns.start(). |
| tests/test_mdns_http_txt.py | Routes HTTP TXT mDNS tests through monitor.mdns. |
| tests/test_mdns_cache_reconcile.py | Moves cache reconcile calls to monitor.mdns.reconcile_from_cache. |
| tests/test_importable_discovery.py | Switches importable discovery tests to monitor.importable. |
| tests/test_dns_cache.py | Updates ping-sweep calls and DNS-cache reads to monitor.state.dns_cache. |
| tests/test_dashboard_advertise.py | Updates advertise tests to patch MdnsSource.zeroconf rather than a monitor facade. |
| tests/test_api_reviver.py | Updates reviver tests to use monitor.ping and monitor.api_reviver. |
| tests/test_api_info_fallback.py | Updates API-info tests to use monitor.api_info and monitor.mdns.reconcile_from_cache. |
| tests/controllers/firmware/test_refresh.py | Updates reprobe assertions to state_monitor.api_info.request_reprobe. |
| tests/controllers/devices/test_subscribe_reachability.py | Adjusts device controller tests to stub state_monitor.mdns.* and state_monitor.importable.*. |
| tests/controllers/devices/conftest.py | Refactors RecordingStateMonitor to provide typed nested fakes for mdns/importable/api_info and state.dns_cache. |
| esphome_device_builder/controllers/devices/scan_change.py | Routes REMOVED handling through state_monitor.importable.revisit_all_importables(). |
| esphome_device_builder/controllers/devices/reachability.py | Uses state_monitor.mdns for TTL reads and refresh calls. |
| esphome_device_builder/controllers/devices/importable.py | Uses state_monitor.mdns.get_cached_addresses and state_monitor.importable.probe_device. |
| esphome_device_builder/controllers/devices/helpers.py | Uses monitor.mdns.get_cached_addresses and monitor.state.dns_cache.get_cached_addresses. |
| esphome_device_builder/controllers/devices/firmware_sync.py | Routes version reprobe to state_monitor.api_info.request_reprobe. |
| esphome_device_builder/controllers/devices/controller.py | Connects reachability tracker and zeroconf access via state_monitor.mdns. |
| esphome_device_builder/controllers/_device_state_monitor/shared.py | Switches shared helpers to use the new public source seams. |
| esphome_device_builder/controllers/_device_state_monitor/ping.py | Uses monitor.mdns.get_cached_addresses within ping resolve fallback. |
| esphome_device_builder/controllers/_device_state_monitor/mdns.py | Uses monitor.importable via the public seam during start/setup. |
| esphome_device_builder/controllers/_device_state_monitor/importable.py | Routes probe/resolve paths through monitor.mdns via the public seam. |
| esphome_device_builder/controllers/_device_state_monitor/controller.py | Promotes sources to public attributes, drops PLR0904, removes delegator methods, and adds invalidate_persisted_ip. |
| esphome_device_builder/controllers/_device_state_monitor/api_reviver.py | Switches ICMP/ping access to monitor.ping and invalidation to monitor.invalidate_persisted_ip. |
| esphome_device_builder/controllers/_device_state_monitor/api_info.py | Routes cache reconciliation through monitor.mdns.reconcile_from_cache. |
| CLAUDE.md | Updates documentation reference from request_version_reprobe to api_info.request_reprobe. |
Merging this PR will not alter performance
Comparing Footnotes
|
|
ESPHome Bot (@esphbot) review |
PR Review — Expose DeviceStateMonitor sources as public seams and drop the PLR0904 grandfatherClean, behavior-preserving refactor — merge-ready.
No behavior change, no security/error-handling/performance surface touched. Coverage moves with the surface (100% on the touched source modules). Checklist
Automated review by Kōan (Claude) |
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
No blocking issues found.
What does this implement/fix?
DeviceStateMonitorcarried a grandfathered# noqa: PLR0904(26 public defs vs the cap of 20), which froze its public surface — so in-package siblings reached private internals directly:shared.pyusedmonitor._mdns(has_live_ptr,resolve_and_claim,zeroconf) and the API reviver usedmonitor._ping(icmp_available,icmp_concurrency,ping_once) and the rawmonitor._on_persisted_ip_invalidatedcallback.This PR does the surface refactor and adds the sanctioned seams, with no behaviour change:
monitor.mdns,monitor.ping,monitor.importable,monitor.api_info,monitor.api_reviver. Per-source queries and nudges route through them;shared.pyandapi_reviver.pyno longer touch_-prefixed monitor attributes.zeroconfproperty,refresh_mdns,get_mdns_a_record_ttl_remaining,get_mdns_cache_info,get_cached_addresses,reconcile_from_mdns_cache,probe_device,revisit_importable,revisit_all_importables,get_importable_devices,request_version_reprobe,get_cached_dns_addresses); callers use the public source attributes (ormonitor.state.dns_cachefor the DNS-cache read).invalidate_persisted_ip(name, stale_ip)folds the_on_persisted_ip_invalidated is not Noneguard so the reviver calls it unconditionally. (The issue's other named seams already exist post-Revive stuck-offline devices from the persisted IP after identity verification #2014:ping.icmp_available,ping.ping_once, andshared.apply_ping_resultas the None-guardedrecord_ping_rttwrapper.)apply_*dedupe family,probe_device_ping,probe_reachability) — 15 public defs, so the PLR0904 noqa is dropped with 5 methods of headroom.tests/controllers/devices/conftest.py'sRecordingStateMonitormirrors the new surface with nested typed sub-fakes sharing the onecallslist; call-tuple names are unchanged so existing assertions kept their meaning.Reviewer notes — two reroutes change the method name, not just the path (the deleted delegators had renamed their targets):
monitor.reconcile_from_mdns_cache(name)→monitor.mdns.reconcile_from_cache(name)monitor.request_version_reprobe(name)→monitor.api_info.request_reprobe(name)revisit_importableandget_importable_deviceshad no production callers on the monitor (theDevicesControllermethod of the same name readscontroller.state.import_result); their behaviour is still covered by tests throughmonitor.importable.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.