Skip to content

Wire pump BLE heartbeat to CGM reading schedule + preserve manager state on missing plugin#2461

Open
loopkitdev wants to merge 2 commits into
LoopKit:next-devfrom
loopkitdev:o5-integration
Open

Wire pump BLE heartbeat to CGM reading schedule + preserve manager state on missing plugin#2461
loopkitdev wants to merge 2 commits into
LoopKit:next-devfrom
loopkitdev:o5-integration

Conversation

@loopkitdev

@loopkitdev loopkitdev commented Jul 18, 2026

Copy link
Copy Markdown

Summary

Wires the pump BLE heartbeat to the CGM reading schedule (uses the coupled LoopKit setBLEHeartbeatRequest API) and hardens device-manager restore:

  • DeviceDataManager.updatePumpManagerBLEHeartbeatPreference sends a PumpHeartbeatRequest (last CGM reading date + expected interval) when the pump must provide the heartbeat, or nil when the CGM wakes the app itself; refreshed after every CGM reading.
  • Preserve persisted pump/CGM state when a plugin can't be instantiated. Previously, launching a build missing a plugin assigned pumpManager/cgmManager = nil, whose didSet deleted the persisted state — permanently wiping the pod pairing (incl. session keys) or CGM config. Now it logs and leaves the saved state on disk for a later build that includes the plugin.

⚠️ Coupling — must merge together

Requires the LoopKit setBLEHeartbeatRequest PR to compile; pairs with the OmnipodKit PR. Merge together. (Cross-links below.)

🤖 Generated with Claude Code

https://claude.ai/code/session_017Tbv6GBAMmGATWp6zwBDy7

Coupled PRs — merge together (three-way dependency)

Loop and OmnipodKit will not compile without the LoopKit protocol change; land all three together and bump the LoopWorkspace next-dev submodule pins in one commit.

ps2 added 2 commits July 14, 2026 20:21
Send the pump a PumpHeartbeatRequest (last CGM reading date + expected reading
interval) when it must provide the BLE heartbeat, or nil when the CGM wakes the
app itself, via the new setBLEHeartbeatRequest API. The last-reading time is
refreshed after every CGM reading (processCGMReadingResult already calls
updatePumpManagerBLEHeartbeatPreference), so the pump's heartbeat cadence tracks
the actual reading schedule.
instantiateDeviceManagers restored a manager by assigning pumpManager/cgmManager
= the result of ...FromRawValue(...). When the plugin wasn't available in the
running build, that returned nil, and the nil assignment fired the didSet, which
wrote rawPumpManager/rawCGMManager = nil and DELETED the persisted state — so
launching a build missing a plugin permanently wiped the pod pairing (incl.
session keys) or CGM config.

Only assign when the manager instantiates; otherwise log and leave the saved
state on disk so a later build that includes the plugin can restore it.
@marionbarker

Copy link
Copy Markdown
Contributor

Test

I'm putting test notes in comments for this PR so they are in one place.

Summary from initial testing: intermittent success

  • When looping while locked, the intervals are sometimes 5 minutes and sometimes 10 minutes
  • But sometimes, signal is lost while locked and no reconnection happens until app is reopened

Configuration

I started with LoopWorkspace next-dev commit 14b70bd.
I downloaded the patch files from Loop #2461, LoopKit 596 and used git apply to modify those 2 submodules.
I pointed directly to the loopkitdev o5-integration branch of OmnipodKit, commit fdafb4a.

I am running 2 test phones:

  • SE 2nd gen, iOS 18
  • SE 3rd gen, iOS 26

Narrative

  • 2026-07-18, around 17:00 to both phones: The first time I built I did not do a clean build folder, so I think the update was not clean
    • SE 3rd gen was already connected to an rPi DASH, continued that connection
    • SE 2nd gen was not connected to a pump: Added Ominpod 5 (PH1K04182331) to phone connection
      • When locked, loop went red

2nd gen, Omnipod 5 narrative

2026-07-19 06:16 lock 2nd gen (o5) phone

3rd gen, rPi DASH narrative

  • 2026-07-18 20:00: realized this phone was not looping while Loop app in the background; was from the original build (without cleaning build folder), so built again
    • observe that rPi is continuing to interact with the phone (see it in terminal) while phone is locked
  • 2026-07-19 06:07:

2026-07-19 06:16 lock 3rd gen (rPi DASH) phone

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.

3 participants