Skip to content

feat: Decode battery temperature from the battery characteristic - #96

Merged
sopelj merged 1 commit into
sopelj:mainfrom
gwhillhouse:battery-temperature
Sep 16, 2026
Merged

sopelj merged 1 commit into
sopelj:mainfrom
gwhillhouse:battery-temperature

Conversation

@gwhillhouse

Copy link
Copy Markdown
Contributor

The battery characteristic (fc540007) is 5 bytes: percent, charging flag, a little-endian uint16 battery temperature in °C×100 (bytes 2–3, same encoding as the other temperatures), and a legacy voltage byte. BatteryInfo.from_bytes only read the first two.

This adds BatteryInfo.temperature (°C, None when the field is zero so mugs that don't report it keep the old behaviour), carries it across the charger push events so a CHARGER_CONNECTED/DISCONNECTED event doesn't wipe it, and appends it to str(BatteryInfo).

Verified on an Ember Mug 2 (14 oz, firmware 406): 06 01 f8 11 00 → 6 %, on base, 46.00 °C. That reading is also the practical reason to expose it: a mug holding a hot drink on the coaster sits at the same percentage for an hour because the pack is above the ~45 °C charging cutoff, and the temperature makes that visible instead of looking like a dead battery. orlopau's notes document the same bytes: https://github.com/orlopau/ember-mug/blob/master/docs/battery.md

  • pytest: 177 passed
  • ruff check / ruff format --check: clean
  • No change to existing as_dict() keys other than the new temperature field; existing 2-byte test still passes unchanged apart from asserting temperature is None.

I left CHANGELOG.md alone since you seem to write it at release time; happy to add a line if you'd prefer.

The battery characteristic (fc540007) is 5 bytes: percent, charging flag,
a little-endian uint16 battery temperature in °C×100 (bytes 2-3, same
encoding as the other temperatures) and a legacy voltage byte. Only the
first two were read. Expose the temperature as `BatteryInfo.temperature`
(None when the field is zero, as on mugs that don't report it), keep it
across charger push events, and include it in `str(BatteryInfo)`.

Verified on an Ember Mug 2 (14 oz, firmware 406): `06 01 f8 11 00` reads
as 6 %, on base, 46.00 °C, which also explains why a hot mug sits on the
coaster without charging (the pack is throttled above ~45 °C).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013XH9XQdJjc83aEz8PuxWAy
@gwhillhouse

Copy link
Copy Markdown
Contributor Author

Context for where this came from, and the statistics-stream decode, is in #97.

@sopelj sopelj left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks for adding this. Good work! I'll test it on my mug and then create a release.

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.79%. Comparing base (1bf20c1) to head (f30e22e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #96      +/-   ##
==========================================
+ Coverage   91.73%   91.79%   +0.05%     
==========================================
  Files          11       11              
  Lines        1029     1036       +7     
  Branches      127      129       +2     
==========================================
+ Hits          944      951       +7     
  Misses         64       64              
  Partials       21       21              

☔ 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.

@sopelj
sopelj merged commit bbff974 into sopelj:main Sep 16, 2026
3 checks passed
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