Repository navigation
feat: add battery_replaced_timestamp property to Tile - #793
Merged
Merged
Conversation
The Tile API records when a Tile's battery was last replaced, in `result.metadata.battery_replaced_at` as epoch milliseconds, but `Tile` exposes no property for it. Return it the same way `last_timestamp` and `lost_timestamp` are returned: a naive UTC `datetime`, or `None` when the key is absent. Only Tiles with a user-replaceable battery that has actually been replaced carry the key, so absence is the common case rather than an error. The neighbouring `metadata.battery_state` is deliberately left out. It is a modelled estimate rather than a reading: a Tile silent for over a year with a flat cell still reported `"40"`, and Tiles with no battery data report a placeholder `"10"`, which this repo's own fixture also carries. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qui3EQaoxiVRCBVVe9waLw
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #793 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 181 187 +6
=========================================
+ Hits 181 187 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bachya
approved these changes
Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe what the PR does:
Follow-up to #792, as offered there. Adds a
battery_replaced_timestampproperty toTile, plus itsas_dict()entry,README.mddocumentation and tests.The Tile API records when a Tile's battery was last replaced, in
result.metadata.battery_replaced_at, as epoch milliseconds in a string. The propertyreturns it the same way
last_timestampandlost_timestampare returned: a naive UTCdatetime, orNonewhen the key is absent. Only Tiles with a user-replaceable batterythat has actually been replaced carry the key, so absence is the common case, not an
error.
Observed on a live account:
metadata{"battery_state": "50", "battery_replaced_at": "1730646298403"}{"battery_state": "40", "battery_replaced_at": "1717167972131"}{"battery_state": "10"}{}Tests:
tile_details_response.jsongains abattery_replaced_atvalue, so thepopulated path is covered.
tile_details_missing_last_state_response.jsonalready has anempty
metadatablock, which covers theNonepath.Deliberately not included:
metadata.battery_state. As described in #792, it is amodelled estimate, not a measurement. A Tile that had not reported for 406 days, with a
flat cell, still showed
"40". Tiles with no battery data show a placeholder"10", thesame value this repo's fixture carries next to
"battery_status": "NONE". A consumerwould reasonably read it as a battery percentage, and it would be wrong in exactly the
case that matters.
battery_replaced_atis a recorded fact, so it is the one worthexposing.
Does this fix a specific issue?
Relates to #107 (closed by #792). This adds the
second piece of battery information discussed there.
Checklist:
README.mdwith any new documentation.Verified locally by running the repo's full pre-commit suite through Poetry against
dev(every hook passes, including pylint), and pytest (12 passed, 100% coverage).🤖 Generated with Claude Code
https://claude.ai/code/session_01Qui3EQaoxiVRCBVVe9waLw