Skip to content

Pairing 2/6: bind scans to the selected band - #692

Draft
mikenrafter wants to merge 4 commits into
OpenStrap:mainfrom
mikenrafter:split/669-choice
Draft

mikenrafter wants to merge 4 commits into
OpenStrap:mainfrom
mikenrafter:split/669-choice

Conversation

@mikenrafter

@mikenrafter mikenrafter commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Section 2 of the split requested in #669. Draft until preceding sections land. This upstream PR temporarily includes those dependencies; review this section through the link below.

Pass the selected remote ID and generation through PairingScreen, AppState and transport. A non-ASK scan skips a different device or a conflicting advertised generation.

On iOS 18+, AccessorySetupKit's system sheet chooses the band. This scan predicate does not constrain that sheet, and there is no selected-row check after connect. A name-only advertisement also cannot establish generation; discovery must identify it.

Individual section diff.

Validation: local localization generation and full flutter analyze --no-pub pass. Focused test files pass: pairing_choice_test, gen5_pairing_filter_test and ui2_tokens_test. Physical iPhone testing remains outstanding.
Upstream review order: 1 ready → 2 draft → 3 draft → 4 draft → 5 draft → 6 draft. All target upstream main; draft diffs include preceding dependencies. Use the individual section link above to review this section alone.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • 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.

Share

@sourcery-ai

sourcery-ai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Schema and migrations

Make device upserts transactional so a failed update cannot leave a partially inserted device row.

  • lib/data/db.dart L3325-3333

Data structures

Add registry role, physical-kind, and main-device metadata, then assign it to each supported device entry.

  • lib/ble/adapters/_registry.dart L313-330, L466-482, L501-505 (+13 small edits)

Define the band identity, evidence, pairing confirmation, paired-device, outcome, and pairing-I/O data structures used across discovery and pairing.

  • lib/ble/band_identity.dart L1-12, L76-197

API

Expose a scan-choice predicate that rejects a different remote ID or a conflicting advertised generation while allowing unknown-generation advertisements.

  • lib/ble/ble_state.dart L1927-1937

Extend the transport scan interface to accept the chosen remote ID and generation, and apply that choice while accepting scan results.

  • lib/ble/transport.dart L24-36, L87-89

Pass the selected device identity through AppState to the transport scan.

  • lib/state/app_state.dart L4632-4634

Allow PairingScreen to receive the selected entry and remote ID for non-AccessorySetupKit pairing.

  • lib/ui2/onboarding/pairing.dart L18, L114-119

Change notify-sensor pairing to return a typed outcome and accept scan evidence and an explicit device-bound confirmation.

  • lib/ble/hrs_link.dart L834-837, L842-843

Uses of the API

Pass the selected remote ID and entry generation into non-AccessorySetupKit scans.

  • lib/ui2/onboarding/pairing.dart L141-142

Supply the candidate's band evidence to notify-sensor pairing and translate its typed outcome for the picker.

  • lib/ui2/pairing/device_picker.dart L45, L200-201

Carry candidate band evidence through the profile sensor-pairing path and translate pairing outcomes for display.

  • lib/ui2/profile/pair_sensor.dart L62-64, L284-286, L325-330

Implementation

Centralize UUID normalization and band identity matching, preserve ranked per-device scan evidence, and implement the injected pairing decision and persistence flow.

  • lib/ble/band_identity.dart L13-75

Refactor sensor scanning to retain band evidence, preserve the first adapter claim across system-device queries, and construct candidates with both sensor and band identity.

  • lib/ble/hrs_link.dart L374-392, L417-422, L468-609 (+8 small edits)

Delegate connected-device pairing to the shared decision flow, recheck band evidence before saving, and adapt Bluetooth discovery, characteristic checks, bonding, and persistence to the pairing interface.

  • lib/ble/hrs_link.dart L845, L850-872, L1393-1557

Add registry-level hinted-name matching for reuse by identity and scan logic.

  • lib/ble/adapters/_registry.dart L1096-1119 (+3 small edits)

UI

Add localized user-facing text for a band refusal, preserving uncertainty when only a WHOOP name identifies the device.

  • lib/ui2/pairing/pair_outcome_text.dart L1-17

Update pairing-related localization resources for the new band-refusal message.

  • lib/l10n/app_de.arb L3475-3476
  • lib/l10n/app_en.arb L16346-16354
  • lib/l10n/app_es.arb L2895-2896
  • lib/l10n/app_fr.arb L2866-2867
  • lib/l10n/app_hi.arb L2866-2867
  • lib/l10n/app_ru.arb L7910-7918
  • lib/l10n/app_th.arb L16331-16340
  • lib/l10n/app_zh.arb L2866-2867

Tests

Cover band identity matching, evidence ranking, safe pairing outcomes, atomic persistence, device roles, and scan-choice binding.

  • test/band_identity_test.dart L1-972
  • test/paired_device_test.dart L196-217
  • test/pairing_choice_test.dart L1-16
  • test/pairing_device_role_test.dart L1-72

Update existing candidate and hinted-name tests for the expanded candidate shape and shared matcher.

  • test/device_picker_test.dart L18
  • test/hrs_link_test.dart L586, L592-596, L602-603
  • test/pair_sensor_test.dart L38
  • test/sensor_cap_test.dart L147

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

This branch has not been deployed

No deployments
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