Skip to content

Commit

Permalink
Merge pull request LoopKit#1638 from LoopKit/tidepool-merge
Browse files Browse the repository at this point in the history
Tidepool merge
  • Loading branch information
ps2 authored Mar 17, 2022
2 parents 17b8748 + cdb902e commit 54506bc
Show file tree
Hide file tree
Showing 18 changed files with 205 additions and 199 deletions.
9 changes: 9 additions & 0 deletions Common/FeatureFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct FeatureFlagConfiguration: Decodable {
let simulatedCoreDataEnabled: Bool
let siriEnabled: Bool
let simpleBolusCalculatorEnabled: Bool
let usePositiveMomentumAndRCForManualBoluses: Bool

fileprivate init() {
// Swift compiler config is inverse, since the default state is enabled.
Expand Down Expand Up @@ -158,6 +159,13 @@ struct FeatureFlagConfiguration: Decodable {
#else
self.simpleBolusCalculatorEnabled = false
#endif

// Swift compiler config is inverse, since the default state is enabled.
#if DISABLE_POSITIVE_MOMENTUM_AND_RC_FOR_MANUAL_BOLUSES
self.usePositiveMomentumAndRCForManualBoluses = false
#else
self.usePositiveMomentumAndRCForManualBoluses = true
#endif
}
}

Expand All @@ -184,6 +192,7 @@ extension FeatureFlagConfiguration : CustomDebugStringConvertible {
"* manualDoseEntryEnabled: \(manualDoseEntryEnabled)",
"* allowDebugFeatures: \(allowDebugFeatures)",
"* simpleBolusCalculatorEnabled: \(simpleBolusCalculatorEnabled)",
"* usePositiveMomentumAndRCForManualBoluses: \(usePositiveMomentumAndRCForManualBoluses)",
].joined(separator: "\n")
}
}
Expand Down
3 changes: 0 additions & 3 deletions Common/Models/WatchContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ final class WatchContext: RawRepresentable {
var recommendedBolusDose: Double?

var potentialCarbEntry: NewCarbEntry?
var recommendedBolusDoseConsideringPotentialCarbEntry: Double?

var cob: Double?
var iob: Double?
Expand Down Expand Up @@ -95,7 +94,6 @@ final class WatchContext: RawRepresentable {
if let rawPotentialCarbEntry = rawValue["pce"] as? NewCarbEntry.RawValue {
potentialCarbEntry = NewCarbEntry(rawValue: rawPotentialCarbEntry)
}
recommendedBolusDoseConsideringPotentialCarbEntry = rawValue["rbce"] as? Double
cob = rawValue["cob"] as? Double

cgmManagerState = rawValue["cgmManagerState"] as? CGMManager.RawStateValue
Expand Down Expand Up @@ -140,7 +138,6 @@ final class WatchContext: RawRepresentable {
raw["r"] = reservoir
raw["rbo"] = recommendedBolusDose
raw["pce"] = potentialCarbEntry?.rawValue
raw["rbce"] = recommendedBolusDoseConsideringPotentialCarbEntry
raw["rp"] = reservoirPercentage

raw["pg"] = predictedGlucose?.rawValue
Expand Down
4 changes: 0 additions & 4 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
437AFEE8203689FE008C4892 /* LoopKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43F78D4B1C914197002152D1 /* LoopKit.framework */; };
437CEEE41CDE5C0A003C8C80 /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437CEEE31CDE5C0A003C8C80 /* UIImage.swift */; };
437D9BA31D7BC977007245E8 /* PredictionTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437D9BA21D7BC977007245E8 /* PredictionTableViewController.swift */; };
438172D91F4E9E37003C3328 /* NewPumpEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 438172D81F4E9E37003C3328 /* NewPumpEvent.swift */; };
4389916B1E91B689000EEF90 /* ChartSettings+Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4389916A1E91B689000EEF90 /* ChartSettings+Loop.swift */; };
438D42F91D7C88BC003244B0 /* PredictionInputEffect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 438D42F81D7C88BC003244B0 /* PredictionInputEffect.swift */; };
438D42FB1D7D11A4003244B0 /* PredictionInputEffectTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 438D42FA1D7D11A4003244B0 /* PredictionInputEffectTableViewCell.swift */; };
Expand Down Expand Up @@ -864,7 +863,6 @@
437CEEE31CDE5C0A003C8C80 /* UIImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = "<group>"; };
437D9BA11D7B5203007245E8 /* Loop.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Loop.xcconfig; sourceTree = "<group>"; };
437D9BA21D7BC977007245E8 /* PredictionTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PredictionTableViewController.swift; sourceTree = "<group>"; };
438172D81F4E9E37003C3328 /* NewPumpEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewPumpEvent.swift; sourceTree = "<group>"; };
438991661E91B563000EEF90 /* ChartPoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartPoint.swift; sourceTree = "<group>"; };
4389916A1E91B689000EEF90 /* ChartSettings+Loop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ChartSettings+Loop.swift"; sourceTree = "<group>"; };
438A95A71D8B9B24009D12E1 /* CGMBLEKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CGMBLEKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -2020,7 +2018,6 @@
A9CBE459248ACBE1008E7BA2 /* DosingDecisionStore+SimulatedCoreData.swift */,
A9F703742489C9A000C98AD8 /* GlucoseStore+SimulatedCoreData.swift */,
A9DCF2D525B0F3C500C89088 /* LoopUIColorPalette+Default.swift */,
438172D81F4E9E37003C3328 /* NewPumpEvent.swift */,
89E267FE229267DF00A3F2AF /* Optional.swift */,
A967D94B24F99B9300CDDF8A /* OutputStream.swift */,
895FE0942201234000FCF18A /* OverrideSelectionViewController.swift */,
Expand Down Expand Up @@ -3535,7 +3532,6 @@
E98A55EF24EDD6E60008715D /* DosingDecisionStoreProtocol.swift in Sources */,
C165B8CE23302C5D0004112E /* RemoteCommand.swift in Sources */,
E9C00EF524C623EF00628F35 /* LoopSettings+Loop.swift in Sources */,
438172D91F4E9E37003C3328 /* NewPumpEvent.swift in Sources */,
4389916B1E91B689000EEF90 /* ChartSettings+Loop.swift in Sources */,
C178249A1E1999FA00D9D25C /* CaseCountable.swift in Sources */,
B4F3D25124AF890C0095CE44 /* BluetoothStateManager.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Loop.xcodeproj/xcshareddata/xcschemes/WatchApp.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
</Scheme>
41 changes: 20 additions & 21 deletions Loop/Extensions/DoseStore+SimulatedCoreData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ extension DoseStore {

fileprivate extension PersistedPumpEvent {
static func simulatedAlarm(date: Date) -> PersistedPumpEvent {
return simulated(date: date, type: .alarm)
return simulated(date: date, type: .alarm, alarmType: .other("Simulated Other Alarm"))
}

static func simulatedAlarmClear(date: Date) -> PersistedPumpEvent {
Expand All @@ -141,19 +141,19 @@ fileprivate extension PersistedPumpEvent {

static func simulatedBasal(date: Date, duration: TimeInterval, rate: Double) -> PersistedPumpEvent {
return simulated(dose: DoseEntry(type: .basal,
startDate: date,
endDate: date.addingTimeInterval(duration),
value: rate,
unit: .unitsPerHour,
deliveredUnits: rate * duration / .hours(1)))
startDate: date,
endDate: date.addingTimeInterval(duration),
value: rate,
unit: .unitsPerHour,
deliveredUnits: rate * duration / .hours(1)))
}

static func simulatedBolus(date: Date, amount: Double) -> PersistedPumpEvent {
return simulated(dose: DoseEntry(type: .bolus,
startDate: date,
endDate: date.addingTimeInterval(.minutes(1)),
value: amount,
unit: .units))
startDate: date,
endDate: date.addingTimeInterval(.minutes(1)),
value: amount,
unit: .units))
}

static func simulatedPrime(date: Date) -> PersistedPumpEvent {
Expand All @@ -174,15 +174,15 @@ fileprivate extension PersistedPumpEvent {

static func simulatedTempBasal(date: Date, duration: TimeInterval, rate: Double, scheduledRate: Double) -> PersistedPumpEvent {
return simulated(dose: DoseEntry(type: .tempBasal,
startDate: date,
endDate: date.addingTimeInterval(duration),
value: rate,
unit: .unitsPerHour,
deliveredUnits: rate * duration / .hours(1),
scheduledBasalRate: HKQuantity(unit: .internationalUnitsPerHour, doubleValue: scheduledRate)))
startDate: date,
endDate: date.addingTimeInterval(duration),
value: rate,
unit: .unitsPerHour,
deliveredUnits: rate * duration / .hours(1),
scheduledBasalRate: HKQuantity(unit: .internationalUnitsPerHour, doubleValue: scheduledRate)))
}

private static func simulated(date: Date, type: PumpEventType) -> PersistedPumpEvent {
private static func simulated(date: Date, type: PumpEventType, alarmType: PumpAlarmType? = nil) -> PersistedPumpEvent {
return PersistedPumpEvent(date: date,
persistedDate: date,
dose: nil,
Expand All @@ -191,8 +191,8 @@ fileprivate extension PersistedPumpEvent {
raw: Data(UUID().uuidString.utf8),
title: UUID().uuidString,
type: type,
isMutable: false,
automatic: nil)
automatic: nil,
alarmType: alarmType)
}

private static func simulated(dose: DoseEntry) -> PersistedPumpEvent {
Expand All @@ -203,8 +203,7 @@ fileprivate extension PersistedPumpEvent {
objectIDURL: URL(string: "x-coredata:///PumpEvent/\(UUID().uuidString)")!,
raw: Data(UUID().uuidString.utf8),
title: String(describing: dose),
type: dose.type.pumpEventType!,
isMutable: false,
type: dose.type.pumpEventType,
automatic: nil)
}
}
27 changes: 0 additions & 27 deletions Loop/Extensions/NewPumpEvent.swift

This file was deleted.

21 changes: 14 additions & 7 deletions Loop/Managers/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ final class DeviceDataManager {
dosingDecisionStore: dosingDecisionStore,
glucoseStore: glucoseStore,
settingsStore: settingsManager.settingsStore,
overrideHistory: overrideHistory
overrideHistory: overrideHistory,
insulinDeliveryStore: doseStore.insulinDeliveryStore
)


Expand Down Expand Up @@ -345,6 +346,7 @@ final class DeviceDataManager {
doseStore.delegate = self
dosingDecisionStore.delegate = self
glucoseStore.delegate = self
doseStore.insulinDeliveryStore.delegate = self

setupPump()
setupCGM()
Expand Down Expand Up @@ -694,7 +696,7 @@ extension DeviceDataManager {
return
}

self.loopManager.addRequestedBolus(DoseEntry(type: .bolus, startDate: Date(), value: units, unit: .units), completion: nil)
self.loopManager.addRequestedBolus(DoseEntry(type: .bolus, startDate: Date(), value: units, unit: .units, isMutable: true), completion: nil)
pumpManager.enactBolus(units: units, automatic: automatic) { (error) in
if let error = error {
self.log.error("%{public}@", String(describing: error))
Expand Down Expand Up @@ -1077,10 +1079,6 @@ extension DeviceDataManager: CarbStoreDelegate {
// MARK: - DoseStoreDelegate
extension DeviceDataManager: DoseStoreDelegate {

func doseStoreHasUpdatedDoseData(_ doseStore: DoseStore) {
remoteDataServicesManager.doseStoreHasUpdatedDoseData(doseStore)
}

func doseStoreHasUpdatedPumpEventData(_ doseStore: DoseStore) {
remoteDataServicesManager.doseStoreHasUpdatedPumpEventData(doseStore)
}
Expand All @@ -1105,6 +1103,15 @@ extension DeviceDataManager: GlucoseStoreDelegate {

}

// MARK: - InsulinDeliveryStoreDelegate
extension DeviceDataManager: InsulinDeliveryStoreDelegate {

func insulinDeliveryStoreHasUpdatedDoseData(_ insulinDeliveryStore: InsulinDeliveryStore) {
remoteDataServicesManager.insulinDeliveryStoreHasUpdatedDoseData(insulinDeliveryStore)
}

}

// MARK: - TestingPumpManager
extension DeviceDataManager {
func deleteTestingPumpData(completion: ((Error?) -> Void)? = nil) {
Expand All @@ -1126,7 +1133,7 @@ extension DeviceDataManager {

healthStore.deleteObjects(of: self.doseStore.sampleType, predicate: devicePredicate) { success, deletedObjectCount, error in
if success {
insulinDeliveryStore.test_lastBasalEndDate = nil
insulinDeliveryStore.test_lastImmutableBasalEndDate = nil
}
completion?(error)
}
Expand Down
Loading

0 comments on commit 54506bc

Please sign in to comment.