Make manual G7 pairing robust when other sensors are nearby - #70
Merged
Merged
Conversation
A 4-digit pairing code does not identify a sensor over the air, so with several G7s in range pairing must try each until one matches the code. Two problems made the manual path fail where a scan (which knows the serial and filters to one sensor) succeeded: - On a code mismatch against the last discovered sensor, the run gave up immediately, even with the scan clock still running and the user's own sensor about to advertise. A mismatch in manual entry only means wrong sensor, not wrong code, so keep scanning until the deadline. A scan still stops on a mismatch, since there it is the one intended sensor. - Candidates were ordered only by slot class and discovery order, so a distant neighbour discovered first was tried before the sensor in the user's hand. Order by signal strength within a class as well: the sensor being paired is nearest, so it goes first. RSSI is plumbed from the discovery callback through to the planner. Adds a pairing-screen note that pairing may check several nearby sensors in turn, so a multi-sensor scan does not look stuck.
Comment-only. The intended sensor is usually nearest because the phone is held up to the freshly inserted sensor during pairing, not because it is in the user's hand.
trioneer-dev
pushed a commit
to loopandlearn/G7SensorKit
that referenced
this pull request
Sep 22, 2026
Brings LoopKit#70 (manual pairing robust when other sensors are nearby) and LoopKit#71 (Dexcom Share upload with follower management). LoopKit#67 is now merged upstream, so this is the first merge rather than a rebase onto it. No new shims needed: the new code introduces no LoopQuantity/LoopUnit, no async acknowledgeAlert and no isInoperable, and our adaptations survived the merge untouched.
dnzxy
added a commit
to nightscout/Trio
that referenced
this pull request
Sep 22, 2026
Picks up LoopKit/G7SensorKit#70 (manual pairing robust when other sensors are nearby) and #71 (Dexcom Share upload with follower management), merged into feat/trio-g7-direct. No Trio-side changes needed.
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.
Problem
Users report that entering the 4-digit pairing code manually fails, but scanning the applicator works — with the same code.
A pairing code does not identify a sensor over the air (the advertised
DXCMxxname is unrelated to it). Only a scanned serial identifies the sensor. So with more than one G7 in range the two paths diverge:couldHaveSerial), so the right sensor is tried immediately.A user's device log (multiple sensors present) showed a manual run trying two neighbour sensors — each ending in "This sensor does not match the pairing code entered" — before finally reaching the user's own sensor (its slot held, so deprioritised and discovered last) and pairing successfully ~4½ minutes in. Two things made this fail in practice:
Premature give-up. On a code mismatch against the last currently discovered candidate, the planner gave up immediately (
giveUp→fail) — even with 19 minutes left on the 20-minute scan clock and the user's own sensor about to advertise. Meanwhile the empty-scan watchdog only fires when nothing was found, so "one wrong neighbour" failed instantly while "nothing at all" waited the full timeout.Order ignored proximity. Candidates were ordered by slot class (unheld before held) then discovery order, so a distant neighbour discovered first was tried before the sensor in the user's hand.
Fix
keepScanningWhenExhaustedis off when a serial is known), since there it is the one intended sensor and a mismatch is genuinely a wrong code.G7Sensorignores it; only pairing uses it).Tests
G7PairingPlannerTestsgains coverage for signal-strength ordering (within-class, not across the held/free boundary, unknown-signal fallback, re-ordering on a fresh reading) and for keep-scanning-vs-give-up by mode. All 16 planner tests pass; fullLoopWorkspacebuilds clean.Notes / follow-ups