Repository navigation
Mi Body Composition Scale 2: pin the real 7-byte history count reply - #608
Conversation
The XMTZC05HM answers the history request with 7 bytes, not 3. The composition history test now sends that reply, so it fails on a protocol that cannot read it. Mark the composition scale as verified on hardware; the Mi Smart Scale 2 stays experimental. Needs the openstrap_protocol pin bumped to a commit containing OpenStrap/protocol#81.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Protocol pin and scale verification notes pubspec.yaml, lib/compute/derivation_engine.dart, lib/ble/adapters/miscale.dart, lib/ble/adapters/_registry.dart |
The protocol pin changed. Its comments note Mi Body Composition Scale 2 history-count support and decoder hardening, and state that no algorithm-version bump is required. The adapter documentation records physical verification for the Mi Body Composition Scale 2 and retains the experimental status for the Mi Smart Scale 2. |
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Possibly related PRs
- OpenStrap/edge#612: Adds foreground discovery and syncing for paired Mi Scale devices. This change adds the protocol support for decoding the seven-byte history-count reply used during that sync.
Suggested reviewers: abdulsaheel
Merge Risk: 
Minimal · up to b4c3a
-
The protocol pin and scale verification notes introduce no established runtime, data, security, or availability regression.
Pre-merge checks: 
4
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAlign Mi scale support with the verified XMTZC05HM hardware by testing its real seven-byte history-count response, pinning the compatible OpenStrap protocol revision, and updating device verification documentation while keeping the Mi Smart Scale 2 experimental. Sequence diagram for Mi Body Composition Scale 2 history retrievalsequenceDiagram
participant Test as CompositionHistoryTest
participant Scale as XMTZC05HM
participant Protocol as OpenStrapProtocol
Test->>Scale: history request
Scale-->>Test: 7-byte history-count reply
Test->>Protocol: decode history-count reply
Protocol-->>Test: decoded history count
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pubspec.yaml" line_range="271" />
<code_context>
+ # (R10 gated on packet type, hello/battery parsing, reassembler
+ # truncation semantics, removal of deprecated gen5 APIs). #81 sits on top
+ # of #82, so it cannot be pinned alone.
+ ref: b4fde6ab5589e53154b808f8b2bbb4d01d9c15b5
openstrap_analytics:
git:
</code_context>
<issue_to_address>
**Lost history records are discarded**
When the reassembler reports lost frames during historical sync, including a burst that passes the count gate, `BleEngine._onChunk` ignores `lostFrames`, so the history drain can commit and ACK an incomplete burst; the band then trims records that were never stored, leaving the user with missing history.
Have `_onChunk` account for `lostFrames` and prevent an incomplete burst from reaching commit or ACK.
</issue_to_address>
### Comment 2
<location path="pubspec.yaml" line_range="271" />
<code_context>
+ # (R10 gated on packet type, hello/battery parsing, reassembler
+ # truncation semantics, removal of deprecated gen5 APIs). #81 sits on top
+ # of #82, so it cannot be pinned alone.
+ ref: b4fde6ab5589e53154b808f8b2bbb4d01d9c15b5
openstrap_analytics:
git:
</code_context>
<issue_to_address>
**Pin check fails after repin**
When the pin-consistency test runs with the updated protocol dependency ref, `kProtocolPin` still contains the old SHA, so `db_serve_version_and_reads_test` compares it with the new dependency ref and fails, making the test suite red.
Update `kProtocolPin` to match the protocol ref selected by `pubspec.yaml` and `pubspec.lock`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and if the updated protocol decoder mishandles the 7-byte reply, it could request or decode the wrong scale-history entries and leave incorrect weight measurements in the app. Those records are bounded and can be corrected or re-imported; reverting restores the previous decoder behavior but would not undo any records already written.
Blocking findings: pubspec.yaml:271, pubspec.yaml:271
Needs OpenStrap/protocol#81, which is merged.
The XMTZC05HM answers the history request with 7 bytes, not 3. The composition history test now sends that reply (captured on a real scale), so it fails on a protocol that can't read it. Header comments mark the Composition Scale 2 as verified on hardware; the Mi Smart Scale 2 stays experimental.
The
openstrap_protocolpin is bumped tob4fde6a, the #81 merge commit.Summary by Sourcery
Support the verified Mi Body Composition Scale 2 protocol responses by updating the protocol pin and hardware-backed history test.
Bug Fixes:
Enhancements:
Build:
Tests:
Pin range
89080bctob4fde6ais 41 protocol commits, not only #81: the AGPL license/docs (#80) and #82 decoder-hardening, which #81 sits on top of, so it cannot be pinned alone. #82 gates the R10 decoders on packet type, changes hello/battery parsing, adds reassembler truncation semantics and drops deprecated gen5 APIs. NokAlgoVersionbump here, to keep this PR small. Full suite run against the new pin shows only 3 failures (low_readiness_notification_testx2,health_workout_export_delete_gate_testx1), which fail identically onmain.Not adopted yet: edge does not read the reassembler's new
lostFramessignal on the commit-before-ACK path (follow-up).Summary by CodeRabbit