Skip to content

feat: add battery_replaced_timestamp property to Tile - #793

Merged
bachya merged 1 commit into
bachya:devfrom
axxonite:battery-replaced
Sep 23, 2026
Merged

bachya merged 1 commit into
bachya:devfrom
axxonite:battery-replaced

Conversation

@axxonite

Copy link
Copy Markdown
Contributor

Describe what the PR does:

Follow-up to #792, as offered there. Adds a battery_replaced_timestamp property to
Tile, plus its as_dict() entry, README.md documentation 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 property
returns 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, not an
error.

Observed on a live account:

Tile metadata
Keys {"battery_state": "50", "battery_replaced_at": "1730646298403"}
Wallet {"battery_state": "40", "battery_replaced_at": "1717167972131"}
Three sealed Tiles {"battery_state": "10"}
Phone {}

Tests: tile_details_response.json gains a battery_replaced_at value, so the
populated path is covered. tile_details_missing_last_state_response.json already has an
empty metadata block, which covers the None path.

Deliberately not included: metadata.battery_state. As described in #792, it is a
modelled 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", the
same value this repo's fixture carries next to "battery_status": "NONE". A consumer
would reasonably read it as a battery percentage, and it would be wrong in exactly the
case that matters. battery_replaced_at is a recorded fact, so it is the one worth
exposing.

Does this fix a specific issue?

Relates to #107 (closed by #792). This adds the
second piece of battery information discussed there.

Checklist:

  • Confirm that one or more new tests are written for the new functionality.
  • Run tests and ensure everything passes (with 100% test coverage).
  • Update README.md with 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

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

codecov Bot commented Sep 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ba4ed44) to head (28c92e2).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bachya
bachya merged commit 331d5ba into bachya:dev Sep 23, 2026
10 checks passed
@axxonite
axxonite deleted the battery-replaced branch September 23, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants