Skip to content

Commit 7804046

Browse files
authored
Enable mid-absorption ISF, and update forecast on settings change (#715)
1 parent fd1130e commit 7804046

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

Loop/Managers/LoopDataManager.swift

+14-2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,19 @@ final class LoopDataManager: ObservableObject {
225225
await self.updateDisplayState()
226226
self.notify(forChange: .insulin)
227227
}
228+
},
229+
NotificationCenter.default.addObserver(
230+
forName: .LoopDataUpdated,
231+
object: nil,
232+
queue: nil
233+
) { (note) in
234+
let context = note.userInfo?[LoopDataManager.LoopUpdateContextKey] as! LoopUpdateContext.RawValue
235+
if case .preferences = LoopUpdateContext(rawValue: context) {
236+
Task { @MainActor in
237+
self.logger.default("Received notification of settings changing")
238+
await self.updateDisplayState()
239+
}
240+
}
228241
}
229242
]
230243

@@ -435,8 +448,7 @@ final class LoopDataManager: ObservableObject {
435448
carbAbsorptionModel: carbAbsorptionModel,
436449
recommendationInsulinModel: insulinModel(for: deliveryDelegate?.pumpInsulinType ?? .novolog),
437450
recommendationType: .manualBolus,
438-
automaticBolusApplicationFactor: effectiveBolusApplicationFactor,
439-
useMidAbsorptionISF: false)
451+
automaticBolusApplicationFactor: effectiveBolusApplicationFactor)
440452
}
441453

442454
func loopingReEnabled() async {

Loop/Models/StoredDataAlgorithmInput.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ struct StoredDataAlgorithmInput: AlgorithmInput {
5252

5353
var automaticBolusApplicationFactor: Double?
5454

55-
var useMidAbsorptionISF: Bool
55+
let useMidAbsorptionISF: Bool = true
5656
}

LoopTests/Managers/MealDetectionManagerTests.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ class MealDetectionManagerTests: XCTestCase {
234234
includePositiveVelocityAndRC: true,
235235
carbAbsorptionModel: .piecewiseLinear,
236236
recommendationInsulinModel: ExponentialInsulinModelPreset.rapidActingAdult.model,
237-
recommendationType: .automaticBolus,
238-
useMidAbsorptionISF: false
239-
)
237+
recommendationType: .automaticBolus)
240238

241239
// These tests don't actually run the loop algorithm directly; they were written to take ICE from fixtures, compute carb effects, and subtract them.
242240
let counteractionEffects = counteractionEffects(for: testType)

LoopTests/ViewModels/BolusEntryViewModelTests.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,7 @@ fileprivate class MockBolusEntryViewModelDelegate: BolusEntryViewModelDelegate {
867867
carbAbsorptionModel: .piecewiseLinear,
868868
recommendationInsulinModel: ExponentialInsulinModelPreset.rapidActingAdult,
869869
recommendationType: .manualBolus,
870-
automaticBolusApplicationFactor: 0.4,
871-
useMidAbsorptionISF: false
870+
automaticBolusApplicationFactor: 0.4
872871
)
873872

874873
func fetchData(for baseTime: Date, disablingPreMeal: Bool, ensureDosingCoverageStart: Date?) async throws -> StoredDataAlgorithmInput {

0 commit comments

Comments
 (0)