Repository navigation
Conversation
- Push an immediate Live Activity update when the custom low/high lines change. TIR/TITR use fixed ranges, so this only applies in custom mode. Thresholds are published through writeThresholds() so the effective range is always used. - Refresh the main stats pie when the range lines or range mode change. - Compare reading colors at mmol/L display precision, so two readings that both display as "3.9" get the same color. Applies to the chart, BG text, contact image and the Live Activity widget. mg/dL is unchanged. - Share the rounding via GlucoseConversion.toDisplayedMmol.
…ndary - Route custom low/high line changes through refreshFromCurrentState instead of a separate hand-built Live Activity push, so the dismissed, enabled and in-flight checks apply and picker bursts are debounced. - Use effectiveThresholds() for the contact image so TIR and TITR modes match the chart, BG text and Live Activity. - Add GlucoseBand.of(_:low:high:mmol:) in Shared and use it for the chart, BG text, contact image, stats pie and the Live Activity widget. A reading on a line is low or high, compared at display precision. - Make the stats pie follow the same boundary rule. - Rename normalizeForColorComparison to normalizeToDisplayPrecision and shorten its comment.
Replace the function-reference/closure ternary with plain per-value conversions so the compiler can type-check it.
A reading exactly on the low or high line is now in range, matching the international consensus on time in range (70-180 mg/dL, 3.9-10.0 mmol/L). GlucoseBand, and so the chart, BG text, contact image, stats pie and Live Activity widget, use the inclusive rule at display precision. The TIR screen and GRI keep their inclusive bands and published cutoffs but now compare at display precision, so readings that display the same mmol/L value share a band. Alarm thresholds are unchanged.
Address review on the range color change: - Watch app and complications color readings with GlucoseBand at the displayed unit's precision, so a reading on a line is green there too. - RetroSnapshot uses the shared band, so the scrubbed BG text matches the chart dots. - mg/dL values are rounded to whole numbers before comparing, so a line picked in mmol/L (stored as 70.26) behaves like the 70 it displays. TIR and GRI get the same rounding. - The Live Activity threshold subscriber skips the initial value, so launch no longer refreshes twice.
- High, Low, activation limits and missed bolus alarms now round the reading and the threshold to the display precision of the current unit, so an alarm agrees with the number shown in mmol/L. - BGPicker converts mmol/L to mg/dL with GlucoseConversion.mmolToMgDl instead of a hardcoded 18. Existing saved values need no migration because both sides are rounded before comparing. - Add tests for boundary readings with both conversion factors.
A threshold picked in mmol/L is stored as fractional mg/dL (3.9 becomes 70.2 or 70.26). In mg/dL it now fires at the whole number it displays.
MtlPhil
requested review from
bjorkert,
codebymini and
marionbarker
as code owners
November 14, 2026 19:54
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.
This builds on #777, so please merge that one first. Until then, this PR also shows #777's commits. Once #777 merges, only the alarm change is left: the last two commits (94608b0 and b6d660f), touching the three alarm conditions,
BGPickerandBGDisplayPrecisionTests.This change was split out of #777, as suggested in its review, so that #777 stays limited to colors and stats. It makes the BG alarms use the same rule as the colors: the reading and the threshold are both compared at the precision shown in the user's unit, so an alarm agrees with the number on screen.
Alarms
passesBGLimits) round both the reading and the threshold to display precision before comparing: one decimal in mmol/L, whole numbers in mg/dL.Picker
BGPickerconverts mmol/L withGlucoseConversion.mmolToMgDlinstead of a hardcoded 18. Saved values need no migration, because both sides are rounded before comparing.Tests
BGDisplayPrecisionTestscovers boundary readings in both units and with both conversion factors, and checks that every mmol/L picker value round-trips to the value picked.