Skip to content

gate GET_HELLO gen5 decode on profile - #69

Merged
abdulsaheel merged 1 commit into
mainfrom
fix/gen5-hello-profile-gate
Sep 19, 2026
Merged

abdulsaheel merged 1 commit into
mainfrom
fix/gen5-hello-profile-gate

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

cmdGetHelloModern builds the same 0x91 opcode gen5 uses for GET_HELLO, but with a gen4 profile (see commands.dart). the decode side in parseCommandResponse never checked profile before running the reply through Gen5HelloInfo.parse, unlike every other shared-opcode branch (battery, clock, data range, body location, battery pack info, alarm time, adv name) which all gate on profile.isGen5.

so a gen4 strap answering cmdGetHelloModern with a body >=104 bytes would get its fields read at gen5's fixed offsets — wrong serial, fw version, cpu hex, battery pct, all confidently reported. a shorter gen4 reply just silently drops (Gen5HelloInfo.parse returns null on length).

fix: gate the branch on profile.isGen5, same as its siblings. no known gen4 layout for this opcode yet, so gen4 replies emit nothing rather than guess.

not currently live in edge (grepped, no caller of cmdGetHelloModern there yet) but wrong regardless for the package's own correctness.

dart test: 631 passed, 4 skipped, 0 failed.

Summary by Sourcery

Restrict GET_HELLO response decoding to gen5 profiles to prevent misreporting gen4 device information.

Bug Fixes:

  • Prevent gen4 GET_HELLO responses from being decoded using the gen5 field layout, avoiding incorrect device information.
  • Leave gen4 responses unparsed until their modern-hello response layout is confirmed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of hello responses for supported device generations.
    • Prevented incorrect serial number, firmware, and battery information from being displayed when receiving incompatible responses.
    • Ensured unsupported hello responses are ignored instead of being misinterpreted.

cmdGetHelloModern sends the same 0x91 opcode with a gen4 profile, but the
response decoder ran every 0x91 reply through Gen5HelloInfo.parse
unconditionally. a gen4 reply that happens to be >=104 bytes would get its
fields read at gen5's byte offsets (wrong serial/fw/battery), and a shorter
one would just get dropped. gate it on profile.isGen5 like every other
shared-opcode branch already does.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @abdulsaheel, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days and 4 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 79818d75-cac4-4c04-8048-4e0409742200

📥 Commits

Reviewing files that changed from the base of the PR and between 57d658b and 89ba2ca.

📒 Files selected for processing (1)
  • lib/src/control.dart

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Hello response decoding

Layer / File(s) Summary
Profile-gated hello decoding
lib/src/control.dart
parseCommandResponse now requires profile.isGen5 and status == 1 before calling Gen5HelloInfo.parse. Non-Gen5 replies produce no decoded Gen5 hello data.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: droptabl

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: gating GET_HELLO decoding on the gen5 profile.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR fixes cross-generation decoding by ensuring the shared GET_HELLO opcode is passed to Gen5HelloInfo.parse only for Gen5 profiles, avoiding confidently incorrect Gen4 telemetry while retaining the existing Gen5 and status handling.

Sequence diagram for profile-gated GET_HELLO decoding

sequenceDiagram
    participant Device
    participant Parser as parseCommandResponse
    participant Gen5 as Gen5HelloInfo.parse

    Device->>Parser: GET_HELLO response
    alt profile.isGen5 and status == 1
        Parser->>Gen5: Gen5HelloInfo.parse(body)
        Gen5-->>Parser: decoded Gen5 hello info
    else Gen4 profile or non-success status
        Parser-->>Device: no hello info emitted
    end
Loading

File-Level Changes

Change Details Files
Restrict modern GET_HELLO response decoding to Gen5 profiles.
  • Add a profile.isGen5 guard alongside the existing success-status check.
  • Prevent Gen4 replies from being interpreted with Gen5 fixed offsets until a verified Gen4 layout exists.
  • Preserve existing behavior for valid Gen5 responses and non-success statuses.
lib/src/control.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@abdulsaheel
abdulsaheel merged commit 6d740b3 into main Sep 19, 2026
4 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.

1 participant