Skip to content

Round to supported rate before setting temp basal rate #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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