From 3d21cdc40fc40a02dea0b0b91db124d621d4994a Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sat, 25 Jul 2026 14:48:34 -0500 Subject: [PATCH] Wire pump BLE heartbeat to the CGM reading schedule 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 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. Requires the LoopKit setBLEHeartbeatRequest API on dev (LoopKit dev backport). --- Loop/Managers/DeviceDataManager.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Loop/Managers/DeviceDataManager.swift b/Loop/Managers/DeviceDataManager.swift index ff678a882..3d07128eb 100644 --- a/Loop/Managers/DeviceDataManager.swift +++ b/Loop/Managers/DeviceDataManager.swift @@ -930,7 +930,17 @@ extension DeviceDataManager { } func updatePumpManagerBLEHeartbeatPreference() { - pumpManager?.setMustProvideBLEHeartbeat(pumpManagerMustProvideBLEHeartbeat) + guard pumpManagerMustProvideBLEHeartbeat else { + pumpManager?.setBLEHeartbeatRequest(nil) + return + } + // Tell the pump when the last CGM reading landed and how often readings are expected, so it can + // schedule its next heartbeat to arrive just after the next reading is due (the pump adds its own + // buffer for the remote CGM value to be fetched and stored). + let request = PumpHeartbeatRequest( + lastCGMReadingDate: glucoseStore.latestGlucose?.startDate, + expectedCGMReadingInterval: cgmManager?.expectedGlucoseSampleInterval ?? .minutes(5)) + pumpManager?.setBLEHeartbeatRequest(request) } }