Skip to content

Commit ecd3588

Browse files
authored
Merge pull request #4 from MikePlante1/round-temp-basal
Round to supported rate before setting temp basal rate
2 parents f11abde + 1b7168b commit ecd3588

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

MinimedKit/PumpManager/MinimedPumpManager.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,10 @@ extension MinimedPumpManager: PumpManager {
941941
return state.pumpModel.supportedBasalRates
942942
}
943943

944+
public func roundToSupportedBasalRate(unitsPerHour: Double) -> Double {
945+
return supportedBasalRates.last(where: { $0 <= unitsPerHour }) ?? 0
946+
}
947+
944948
public var supportedBolusVolumes: [Double] {
945949
return state.pumpModel.supportedBolusVolumes
946950
}
@@ -1321,13 +1325,16 @@ extension MinimedPumpManager: PumpManager {
13211325

13221326
self.recents.tempBasalEngageState = .engaging
13231327

1324-
let result = session.setTempBasal(unitsPerHour, duration: duration)
1325-
1328+
// Round to nearest supported rate
1329+
let rate = self.roundToSupportedBasalRate(unitsPerHour: unitsPerHour)
1330+
1331+
let result = session.setTempBasal(rate, duration: duration)
1332+
13261333
switch result {
13271334
case .success:
13281335
let now = self.dateGenerator()
13291336

1330-
let dose = UnfinalizedDose(tempBasalRate: unitsPerHour, startTime: now, duration: duration, insulinType: insulinType, automatic: true)
1337+
let dose = UnfinalizedDose(tempBasalRate: rate, startTime: now, duration: duration, insulinType: insulinType, automatic: true)
13311338

13321339
self.recents.tempBasalEngageState = .stable
13331340

0 commit comments

Comments
 (0)