Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions MinimedKit/PumpManager/MinimedPumpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ extension MinimedPumpManager: PumpManager {
return state.pumpModel.supportedBasalRates
}

public func roundToSupportedBasalRate(unitsPerHour: Double) -> Double {
return supportedBasalRates.last(where: { $0 <= unitsPerHour }) ?? 0
}

public var supportedBolusVolumes: [Double] {
return state.pumpModel.supportedBolusVolumes
}
Expand Down Expand Up @@ -1321,13 +1325,16 @@ extension MinimedPumpManager: PumpManager {

self.recents.tempBasalEngageState = .engaging

let result = session.setTempBasal(unitsPerHour, duration: duration)

// Round to nearest supported rate
let rate = self.roundToSupportedBasalRate(unitsPerHour: unitsPerHour)

let result = session.setTempBasal(rate, duration: duration)

switch result {
case .success:
let now = self.dateGenerator()

let dose = UnfinalizedDose(tempBasalRate: unitsPerHour, startTime: now, duration: duration, insulinType: insulinType, automatic: true)
let dose = UnfinalizedDose(tempBasalRate: rate, startTime: now, duration: duration, insulinType: insulinType, automatic: true)

self.recents.tempBasalEngageState = .stable

Expand Down