Send the mDNS PTR record lifetime, not its remaining TTL#1685
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1685 +/- ##
==========================================
- Coverage 99.54% 99.54% -0.01%
==========================================
Files 227 227
Lines 18142 18134 -8
==========================================
- Hits 18060 18052 -8
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 updates the device reachability payload to send the mDNS PTR record’s full announced lifetime (mdns_ptr_ttl_seconds) rather than its remaining TTL, so the frontend can derive an “offline in N” countdown from the PTR lifetime minus “last seen” age (removing the need for polling).
Changes:
- Replace
mdns_ptr_ttl_remaining_secondswithmdns_ptr_ttl_secondsthroughout the reachability snapshot/event payload. - Remove the
devices/get_reachabilityone-shot WS command (polling no longer needed). - Update API docs and adjust/remove tests accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
esphome_device_builder/controllers/_device_state_monitor/mdns.py |
Emit PTR announced TTL (ptr.ttl) instead of remaining TTL in get_mdns_cache_info. |
esphome_device_builder/controllers/_reachability_tracker.py |
Rename snapshot field to mdns_ptr_ttl_seconds and propagate into the wire snapshot. |
esphome_device_builder/models/devices.py |
Update DeviceReachabilityData TypedDict field name to mdns_ptr_ttl_seconds. |
esphome_device_builder/controllers/devices/controller.py |
Remove the devices/get_reachability API command. |
docs/API.md |
Update devices/subscribe_reachability documentation and remove the devices/get_reachability entry. |
tests/test_state_monitor_reachability.py |
Update assertions to validate PTR lifetime instead of remaining TTL. |
tests/test_reachability_tracker.py |
Update snapshot expectations for renamed PTR TTL field. |
tests/controllers/devices/test_subscribe_reachability.py |
Remove coverage for the deleted devices/get_reachability command. |
|
|
esphbot
left a comment
There was a problem hiding this comment.
No blocking issues found.
The drawer derives its offline countdown as the record lifetime minus the last-seen age, so the value re-anchors in lockstep with last seen instead of tracking the PTR's remaining TTL; the browser refreshes that remaining TTL at ~80% of the lifetime, which drifts against the actively-probed A record and reads out of sync with last seen. Replaces the reachability snapshot's mdns_ptr_ttl_remaining_seconds with mdns_ptr_ttl_seconds (the device's own announced PTR lifetime) and drops devices/get_reachability; the countdown is computed client-side from data the subscription already pushes, so no poll is needed.
f6dd282 to
e27bda7
Compare
PR Review — Send the mDNS PTR record lifetime, not its remaining TTLClean, well-tested follow-up. Merge-ready; only a minor docstring-style nit. Strengths:
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?
Follow-up to #1682. That PR shipped
mdns_ptr_ttl_remaining_secondsplus adevices/get_reachabilityone-shot command so the drawer could poll the PTR's remaining TTL. Testing the live drawer showed the remaining TTL reads out of sync with "last seen": the drawer actively probes the A record (keeping last-seen fresh) while the PTR's remaining TTL is only refreshed by the zeroconf browser at ~80% of the lifetime, so the countdown drifted against last-seen.This sends the PTR's full announced lifetime instead,
mdns_ptr_ttl_seconds(=ptr.ttl, the device's own record lifetime), and the frontend derives the offline countdown as that lifetime minus the last-seen age, so the two move in lockstep on every subscription push. That makes the poll unnecessary, sodevices/get_reachabilityis removed; no extra mDNS traffic is generated.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.