Expose the mDNS PTR record TTL on the reachability snapshot#1682
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1682 +/- ##
=======================================
Coverage 99.54% 99.54%
=======================================
Files 227 227
Lines 18129 18142 +13
=======================================
+ Hits 18047 18060 +13
Misses 82 82
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 extends the per-device reachability snapshot to expose the mDNS PTR record’s remaining TTL so the UI can display an “offline in N seconds” horizon (distinct from the existing freshest-record TTL), and adds a one-shot command to fetch the current snapshot on demand.
Changes:
- Add
mdns_ptr_ttl_remaining_secondstoDeviceReachabilityDataand propagate it throughReachabilityTracker.snapshot. - Extend the mDNS cache reader (
get_mdns_cache_info) to compute and return the PTR record’s remaining TTL separately from the freshest-record TTL. - Add
devices/get_reachabilityWS command and update tests + API docs accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
esphome_device_builder/controllers/_device_state_monitor/mdns.py |
Computes PTR TTL remaining and returns it in MdnsCacheInfo. |
esphome_device_builder/controllers/_reachability_tracker.py |
Adds PTR TTL field to MdnsCacheInfo and includes it in the reachability snapshot wire shape. |
esphome_device_builder/controllers/devices/controller.py |
Adds new devices/get_reachability command returning the current snapshot. |
esphome_device_builder/models/devices.py |
Extends DeviceReachabilityData TypedDict with mdns_ptr_ttl_remaining_seconds. |
docs/API.md |
Documents the new field on reachability events and the new one-shot command. |
tests/test_state_monitor_reachability.py |
Adds coverage for PTR TTL calculation via get_mdns_cache_info. |
tests/test_reachability_tracker.py |
Verifies snapshot includes mdns_ptr_ttl_remaining_seconds. |
tests/controllers/devices/test_subscribe_reachability.py |
Adds tests for devices/get_reachability behavior and NOT_FOUND. |
|
|
esphbot
left a comment
There was a problem hiding this comment.
No blocking issues found.
503d9cd to
0b90c5c
Compare
Adds mdns_ptr_ttl_remaining_seconds to MdnsCacheInfo and the reachability_state payload; it is the PTR record's own remaining TTL, the countdown to the zeroconf Removed event that flips an mDNS owned device offline, distinct from the freshest-record mdns_ttl_remaining_seconds. Adds a one shot devices/get_reachability command so the open drawer can re-read the live value; a pure PTR TTL refresh is deduped by zeroconf and never pushed, so polling is the only way to catch a healthy device re-announcing.
0b90c5c to
d52807f
Compare
PR Review — Expose the mDNS PTR record TTL on the reachability snapshotClean, additive data-exposure change. Merge-ready. The PR surfaces exactly one new nullable field and one one-shot read command, with no behavior change to existing paths. Specific strengths:
The prior Copilot/esphbot comments about polling-cadence text and missing INVALID_MESSAGE reference an earlier revision; the current docstring is already trimmed and validation is already present. Checklist
Automated review by Kōan (Claude) |
esphbot
left a comment
There was a problem hiding this comment.
No blocking issues found.
What does this implement/fix?
People keep filing "offline device still shows online" reports because mDNS is passive and that isn't obvious. An ESPHome device's online state comes from its zeroconf PTR record; when a device powers off without a goodbye the record only ages out after its TTL (commonly around 75 minutes). We deliberately don't actively probe every device on a short interval, since that would flood the network with mDNS traffic.
This is the backend half of surfacing that in the UI. It adds
mdns_ptr_ttl_remaining_secondsto the reachability snapshot (MdnsCacheInfoand thereachability_stateevent); it is the PTR record's own remaining TTL, the countdown to the zeroconfRemovedevent that flips an mDNS owned device offline, kept distinct from the existing freshest-recordmdns_ttl_remaining_seconds(which tracks the ~120s A record the refresh loop renews). It also adds a one shotdevices/get_reachabilitycommand so the open drawer can re-read the live value; a pure PTR TTL refresh is deduped by zeroconf and never pushed, so polling is the only way to catch a healthy device re-announcing. The read is scoped to a single device, not fleet wide.The frontend renders the countdown and does the polling; this PR only exposes the data.
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.