Repository navigation
fix(bee): support 3-byte millivolts battery format and clamp legacy percentage (#21749) - #21768
Conversation
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks for the excellent root-cause analysis on #21749 — the format detection, clamping, and plausibility gate are the right shape for this fix, and the hermetic test suite is genuinely useful. I verified the interpolation independently: 4059 mV maps to 77% (discharging) / 62% (charging) exactly as your tests expect, and both calibration tables are strictly monotonic. However, a few things need fixing before this can merge.
app/lib/services/devices/connectors/bee_connection.dart
- The payload-length branching in
parseBatteryResponseis clean: 2-byte legacy path now clampslevelto 0..100 (previously unclamped), and the 3-byte path decodes little-endian millivolts (payload[0] | (payload[1] << 8)), rejects readings outside 3000–4500 mV, and reads the charging state frompayload[2]. This matches the payload evidence in the issue. - One maintainer note (non-blocking): the
_dischargeStates/_chargingStatestables are a generic LiPo curve rather than officially sourced Bee firmware calibration — the issue author measured ~76% at 4059 mV vs 77% here. Close, but hardware-side confirmation of the curve would strengthen confidence.
app/test/unit/bee_connection_battery_test.dart
- Good coverage: null on short payloads, both formats, clamping, boundary voltages (4200/3400 mV), and out-of-range rejection.
- Blocker: the import of
package:omi/services/devices/models.dartis unused (DeviceTypeandBtDevicecome from the already-importedbt_device.dart). This trips the analyzer ratchet —unused_import: 1 found, baseline 0— and fails Dart Analyze & Tests. Please remove it.
CI failures to address (all contributor-fixable):
Dart Analyze & Tests— the unused import above. Two other lint counts actually improved (curly_braces_in_flow_control_structures6→5,dangling_library_doc_comments1→0); the ratchet output suggests runningapp/scripts/analyze_ratchet.sh --update-baselinein this PR to lock those in.Hygiene(PR Metadata Preflight) — the PR body is missing the required declarations the preflight names: an explicitUI-Evidence: none, theProduct invariants affectedsection, and a validated failure-class declaration per the failure-class protocol. The preflight log lists exactly what to add and how.Mobile Release Eligibility— fails downstream of the above; it should clear once 1 and 2 are fixed.
No security, privacy, dependency, or workflow surfaces touched — this is a well-contained parser fix. Once the mechanical items above are resolved I'd expect this to move quickly.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Thanks @Git-on-my-level! Both items addressed:\n1. Removed the unused models.dart import from �pp/test/unit/bee_connection_battery_test.dart to unblock the Dart analyzer ratchet.\n2. Updated the PR body metadata with all required preflight declarations (UI-Evidence: none, Product invariants affected: none, and Failure-Class: none). |
|
Hi @Git-on-my-level, All CI checks and preflight contracts are now 100% green:
Ready for review and merge! Thank you. |
|
Thank you @kodjima33, @Git-on-my-level, and @mdmohsin7 for reviewing and merging! Glad to have the Bee battery parser accurate and stable. Bounty Claim Details
|
|
Hi @kodjima33, @josancamon19, Following up on bounty settlement for merged PR #21768 (Issue #21749):
Whenever the batch disbursement runs, please confirm. Thank you! |
What changed and why
Fixes #21749 by adding support for newer Bee firmware (e.g. 0.6.20+) 3-byte little-endian millivolts battery responses in BeeDeviceConnection.parseBatteryResponse, while preserving backwards compatibility with legacy 2-byte percentage responses and clamping the legacy level to 0..100.
Product invariants affected
How it was verified
Verified via hermetic Dart unit tests covering both 2-byte percentage and 3-byte millivolts formats, boundary conditions (3400 mV and 4200 mV), charging/discharging curves, and out-of-range rejection (<3000 mV or >4500 mV).
Tests
�pp/test/unit/bee_connection_battery_test.dart
UI evidence
UI-Evidence: none -- Non-UI BLE protocol parser logic verified via hermetic unit tests.
Failure class (fixes)
Failure-Class: none