Repository navigation
feat: Decode battery temperature from the battery characteristic - #96
Merged
Merged
Conversation
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
Contributor
Author
|
Context for where this came from, and the statistics-stream decode, is in #97. |
sopelj
approved these changes
Sep 16, 2026
sopelj
left a comment
Owner
There was a problem hiding this comment.
Awesome! Thanks for adding this. Good work! I'll test it on my mug and then create a release.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
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_bytesonly read the first two.This adds
BatteryInfo.temperature(°C,Nonewhen the field is zero so mugs that don't report it keep the old behaviour), carries it across the charger push events so aCHARGER_CONNECTED/DISCONNECTEDevent doesn't wipe it, and appends it tostr(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.mdpytest: 177 passedruff check/ruff format --check: cleanas_dict()keys other than the newtemperaturefield; existing 2-byte test still passes unchanged apart from assertingtemperature is None.I left
CHANGELOG.mdalone since you seem to write it at release time; happy to add a line if you'd prefer.