From d777479d7c983a37ad18ace8369554c97dd88f74 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sat, 2 Sep 2017 15:25:05 -0500 Subject: [PATCH 1/2] Improve tracking of recent boluses --- Loop.xcodeproj/project.pbxproj | 48 ++++++++++--------- Loop/Extensions/DoseStore.swift | 5 +- Loop/Managers/DeviceDataManager.swift | 40 +++++++++------- Loop/Managers/LoopDataManager.swift | 43 ++++++++++++----- Loop/Managers/WatchDataManager.swift | 6 +-- .../StatusTableViewController.swift | 2 +- 6 files changed, 88 insertions(+), 56 deletions(-) diff --git a/Loop.xcodeproj/project.pbxproj b/Loop.xcodeproj/project.pbxproj index e265ab6ef1..645bc833a5 100644 --- a/Loop.xcodeproj/project.pbxproj +++ b/Loop.xcodeproj/project.pbxproj @@ -74,6 +74,7 @@ 437CCAE01D285C7B0075D2C3 /* ServiceAuthentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437CCADF1D285C7B0075D2C3 /* ServiceAuthentication.swift */; }; 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 */; }; 4381D2261F3C0FDD004ACCF9 /* RileyLinkDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4381D2251F3C0FDD004ACCF9 /* RileyLinkDevice.swift */; }; 43846AD51D8FA67800799272 /* Base.lproj in Resources */ = {isa = PBXBuildFile; fileRef = 43846AD41D8FA67800799272 /* Base.lproj */; }; 43846ADB1D91057000799272 /* ContextUpdatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43846ADA1D91057000799272 /* ContextUpdatable.swift */; }; @@ -447,6 +448,7 @@ 437CEEE31CDE5C0A003C8C80 /* UIImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = ""; }; 437D9BA11D7B5203007245E8 /* Loop.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Loop.xcconfig; sourceTree = ""; }; 437D9BA21D7BC977007245E8 /* PredictionTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PredictionTableViewController.swift; sourceTree = ""; }; + 438172D81F4E9E37003C3328 /* NewPumpEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewPumpEvent.swift; sourceTree = ""; }; 4381D2251F3C0FDD004ACCF9 /* RileyLinkDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RileyLinkDevice.swift; sourceTree = ""; }; 43846AD41D8FA67800799272 /* Base.lproj */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Base.lproj; sourceTree = ""; }; 43846ADA1D91057000799272 /* ContextUpdatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContextUpdatable.swift; sourceTree = ""; }; @@ -888,6 +890,7 @@ 4302F4E41D4EA75100F0FCAF /* DoseStore.swift */, 43C513181E864C4E001547C7 /* GlucoseRangeSchedule.swift */, C15713811DAC6983005BC4D2 /* MealBolusNightscoutTreatment.swift */, + 438172D81F4E9E37003C3328 /* NewPumpEvent.swift */, 43CEE6E51E56AFD400CB9116 /* NightscoutUploader.swift */, 4398973A1CD2FC2000223065 /* NSDateFormatter.swift */, 43E344A31B9E1B1C00C85C07 /* NSUserDefaults.swift */, @@ -1278,7 +1281,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0820; ORGANIZATIONNAME = "LoopKit Authors"; TargetAttributes = { 43776F8B1B8022E90074EA36 = { @@ -1499,7 +1502,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "# /usr/local/bin/carthage build --platform \"$PLATFORM_NAME\" \"$SRCROOT\"\n# Only run this script if we're not using a workspace or installing\nif [ ! -d $PROJECT_DIR/Loop.xcworkspace ] || [ \"$ACTION\" = \"install\" ]; then\n /usr/local/bin/carthage copy-frameworks\nfi"; + shellScript = "# /usr/local/bin/carthage build --platform \"$PLATFORM_NAME\" \"$SRCROOT\"\n# Only run this script if we're not using a workspace or installing\nif [ ! -d $PROJECT_DIR/Loop.xcworkspace ] || [ \"$ACTION\" = \"install\" ]; then\n /usr/local/bin/carthage copy-frameworks\nfi"; }; /* End PBXShellScriptBuildPhase section */ @@ -1560,6 +1563,7 @@ 439BED2A1E76093C00B0AED5 /* CGMManager.swift in Sources */, C18C8C511D5A351900E043FB /* NightscoutDataManager.swift in Sources */, 438849EA1D297CB6003B3F23 /* NightscoutService.swift in Sources */, + 438172D91F4E9E37003C3328 /* NewPumpEvent.swift in Sources */, 437CCADC1D284B830075D2C3 /* ButtonTableViewCell.swift in Sources */, 4389916B1E91B689000EEF90 /* ChartSettings+Loop.swift in Sources */, 4315D2871CA5CC3B00589052 /* CarbEntryEditTableViewController.swift in Sources */, @@ -1838,7 +1842,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer: loudnate@gmail.com (XZN842LDLT)"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 39; + CURRENT_PROJECT_VERSION = 39; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -1866,7 +1870,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0.1; + SWIFT_VERSION = 3.0.1; TARGETED_DEVICE_FAMILY = "1,2"; WARNING_CFLAGS = "-Wall"; }; @@ -1896,7 +1900,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer: loudnate@gmail.com (XZN842LDLT)"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 39; + CURRENT_PROJECT_VERSION = 39; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -1917,7 +1921,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0.1; + SWIFT_VERSION = 3.0.1; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; WARNING_CFLAGS = "-Wall"; @@ -1931,7 +1935,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Loop/Loop.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Loop/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; "OTHER_SWIFT_FLAGS[sdk=iphonesimulator*]" = "-D IOS_SIMULATOR"; @@ -1948,7 +1952,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Loop/Loop.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Loop/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER)"; @@ -1963,7 +1967,7 @@ ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "WatchApp Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).watchkitapp.watchkitextension"; @@ -1981,7 +1985,7 @@ ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "WatchApp Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).watchkitapp.watchkitextension"; @@ -2000,7 +2004,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; IBSC_MODULE = WatchApp_Extension; INFOPLIST_FILE = WatchApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2020,7 +2024,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; IBSC_MODULE = WatchApp_Extension; INFOPLIST_FILE = WatchApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2038,7 +2042,7 @@ buildSettings = { CLANG_ANALYZER_NONNULL = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = DoseMathTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.loudnate.DoseMathTests; @@ -2051,7 +2055,7 @@ buildSettings = { CLANG_ANALYZER_NONNULL = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = DoseMathTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.loudnate.DoseMathTests; @@ -2065,7 +2069,7 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = LoopTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.loudnate.LoopTests; @@ -2080,7 +2084,7 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = LoopTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.loudnate.LoopTests; @@ -2098,7 +2102,7 @@ CODE_SIGN_ENTITLEMENTS = "Loop Status Extension/Loop Status Extension.entitlements"; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "Loop Status Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).statuswidget"; @@ -2117,7 +2121,7 @@ CODE_SIGN_ENTITLEMENTS = "Loop Status Extension/Loop Status Extension.entitlements"; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "Loop Status Extension/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "$(MAIN_APP_BUNDLE_IDENTIFIER).statuswidget"; @@ -2135,11 +2139,11 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; - CURRENT_PROJECT_VERSION = 39; + CURRENT_PROJECT_VERSION = 39; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 39; + DYLIB_CURRENT_VERSION = 39; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = LoopUI/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -2162,11 +2166,11 @@ CLANG_WARN_SUSPICIOUS_MOVES = YES; CODE_SIGN_IDENTITY = ""; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; - CURRENT_PROJECT_VERSION = 39; + CURRENT_PROJECT_VERSION = 39; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 39; + DYLIB_CURRENT_VERSION = 39; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = LoopUI/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/Loop/Extensions/DoseStore.swift b/Loop/Extensions/DoseStore.swift index 26ae992b16..3247fb08ee 100644 --- a/Loop/Extensions/DoseStore.swift +++ b/Loop/Extensions/DoseStore.swift @@ -27,7 +27,10 @@ extension LoopDataManager { switch event.pumpEvent { case let bolus as BolusNormalPumpEvent: - dose = DoseEntry(type: .bolus, startDate: event.date, endDate: event.date.addingTimeInterval(bolus.duration), value: bolus.amount, unit: .units) + // For entries in-progress, use the programmed amount + let units = event.isMutable() ? bolus.programmed : bolus.amount + + dose = DoseEntry(type: .bolus, startDate: event.date, endDate: event.date.addingTimeInterval(bolus.duration), value: units, unit: .units) case is SuspendPumpEvent: dose = DoseEntry(suspendDate: event.date) case is ResumePumpEvent: diff --git a/Loop/Managers/DeviceDataManager.swift b/Loop/Managers/DeviceDataManager.swift index f830855725..0e72688ca1 100644 --- a/Loop/Managers/DeviceDataManager.swift +++ b/Loop/Managers/DeviceDataManager.swift @@ -427,13 +427,16 @@ final class DeviceDataManager { } let setBolus = { - ops.setNormalBolus(units: units) { (error) in - if let error = error { - self.logger.addError(error, fromSource: "Bolus") - notify(error) - } else { - self.loopManager.addExpectedBolus(units, at: Date()) - notify(nil) + self.loopManager.addRequestedBolus(units: units, at: Date()) { + ops.setNormalBolus(units: units) { (error) in + if let error = error { + self.logger.addError(error, fromSource: "Bolus") + notify(error) + } else { + self.loopManager.addConfirmedBolus(units: units, at: Date()) { + notify(nil) + } + } } } } @@ -735,28 +738,33 @@ extension DeviceDataManager: LoopDataManagerDelegate { return } + let notify = { (result: Result) -> Void in + // If we haven't fetched history in a while (preferredInsulinDataSource == .reservoir), + // let's try to do so while the pump radio is on. + if self.loopManager.doseStore.lastAddedPumpEvents.timeIntervalSinceNow < .minutes(-4) { + self.fetchPumpHistory { (_) in + completion(result) + } + } else { + completion(result) + } + } + ops.setTempBasal(rate: basal.rate, duration: basal.duration) { (result) -> Void in switch result { case .success(let body): let now = Date() let endDate = now.addingTimeInterval(body.timeRemaining) let startDate = endDate.addingTimeInterval(-basal.duration) - - completion(.success(DoseEntry( + notify(.success(DoseEntry( type: .tempBasal, startDate: startDate, endDate: endDate, value: body.rate, unit: .unitsPerHour ))) - - // If we haven't fetched history in a while (preferredInsulinDataSource == .reservoir), - // let's try to do so while the pump radio is on. - if self.loopManager.doseStore.lastAddedPumpEvents.timeIntervalSinceNow < .minutes(-4) { - self.fetchPumpHistory { (_) in } - } case .failure(let error): - completion(.failure(error)) + notify(.failure(error)) } } } diff --git a/Loop/Managers/LoopDataManager.swift b/Loop/Managers/LoopDataManager.swift index 14a8a52206..1efb3fbafc 100644 --- a/Loop/Managers/LoopDataManager.swift +++ b/Loop/Managers/LoopDataManager.swift @@ -320,15 +320,34 @@ final class LoopDataManager { } } - /// Adds a bolus enacted by the pump, but not fully delivered. + /// Adds a bolus requested of the pump, but not confirmed. /// /// - Parameters: /// - units: The bolus amount, in units - /// - date: The date the bolus was enacted - func addExpectedBolus(_ units: Double, at date: Date) { + /// - date: The date the bolus was requested + func addRequestedBolus(units: Double, at date: Date, completion: (() -> Void)?) { dataAccessQueue.async { - self.lastBolus = (units: units, date: date) + self.lastRequestedBolus = (units: units, date: date) self.notify(forChange: .bolus) + + completion?() + } + } + + /// Adds a bolus enacted by the pump, but not fully delivered. + /// + /// - Parameters: + /// - units: The bolus amount, in units + /// - date: The date the bolus was enacted + func addConfirmedBolus(units: Double, at date: Date, completion: (() -> Void)?) { + self.doseStore.addPendingPumpEvent(.enactedBolus(units: units, at: date)) { + self.dataAccessQueue.async { + self.lastRequestedBolus = nil + self.insulinEffect = nil + self.notify(forChange: .bolus) + + completion?() + } } } @@ -344,8 +363,8 @@ final class LoopDataManager { if error == nil { self.insulinEffect = nil // Expire any bolus values now represented in the insulin data - if let bolusDate = self.lastBolus?.date, bolusDate.timeIntervalSinceNow < TimeInterval(minutes: -5) { - self.lastBolus = nil + if let bolusDate = self.lastRequestedBolus?.date, bolusDate.timeIntervalSinceNow < TimeInterval(minutes: -5) { + self.lastRequestedBolus = nil } } @@ -372,8 +391,8 @@ final class LoopDataManager { self.dataAccessQueue.async { self.insulinEffect = nil // Expire any bolus values now represented in the insulin data - if areStoredValuesContinuous, let bolusDate = self.lastBolus?.date, bolusDate.timeIntervalSinceNow < TimeInterval(minutes: -5) { - self.lastBolus = nil + if areStoredValuesContinuous, let bolusDate = self.lastRequestedBolus?.date, bolusDate.timeIntervalSinceNow < TimeInterval(minutes: -5) { + self.lastRequestedBolus = nil } completion(.success(( @@ -611,7 +630,7 @@ final class LoopDataManager { pendingTempBasalInsulin = 0 } - let pendingBolusAmount: Double = lastBolus?.units ?? 0 + let pendingBolusAmount: Double = lastRequestedBolus?.units ?? 0 // All outstanding potential insulin delivery return pendingTempBasalInsulin + pendingBolusAmount @@ -699,7 +718,7 @@ final class LoopDataManager { fileprivate var carbsOnBoard: CarbValue? fileprivate var lastTempBasal: DoseEntry? - fileprivate var lastBolus: (units: Double, date: Date)? + fileprivate var lastRequestedBolus: (units: Double, date: Date)? fileprivate var lastLoopCompleted: Date? { didSet { NotificationManager.scheduleLoopNotRunningNotifications() @@ -852,7 +871,7 @@ final class LoopDataManager { } guard - lastBolus == nil, // Don't recommend changes if a bolus was just set + lastRequestedBolus == nil, // Don't recommend changes if a bolus was just set let tempBasal = DoseMath.recommendTempBasalFromPredictedGlucose(predictedGlucose, lastTempBasal: lastTempBasal, maxBasalRate: maxBasal, @@ -1091,7 +1110,7 @@ extension LoopDataManager { "predictedGlucose: \(state.predictedGlucose ?? [])", "retrospectivePredictedGlucose: \(state.retrospectivePredictedGlucose ?? [])", "recommendedTempBasal: \(String(describing: state.recommendedTempBasal))", - "lastBolus: \(String(describing: manager.lastBolus))", + "lastBolus: \(String(describing: manager.lastRequestedBolus))", "lastGlucoseChange: \(String(describing: manager.lastGlucoseChange))", "retrospectiveGlucoseChange: \(String(describing: manager.retrospectiveGlucoseChange))", "lastLoopCompleted: \(String(describing: state.lastLoopCompleted))", diff --git a/Loop/Managers/WatchDataManager.swift b/Loop/Managers/WatchDataManager.swift index eabc1b780d..82170ca6a0 100644 --- a/Loop/Managers/WatchDataManager.swift +++ b/Loop/Managers/WatchDataManager.swift @@ -156,12 +156,10 @@ final class WatchDataManager: NSObject, WCSessionDelegate { if error == nil { AnalyticsManager.shared.didSetBolusFromWatch(bolus.value) } - - replyHandler([:]) } - } else { - replyHandler([:]) } + + replyHandler([:]) default: replyHandler([:]) } diff --git a/Loop/View Controllers/StatusTableViewController.swift b/Loop/View Controllers/StatusTableViewController.swift index 65295329e5..2a9db8e511 100644 --- a/Loop/View Controllers/StatusTableViewController.swift +++ b/Loop/View Controllers/StatusTableViewController.swift @@ -49,7 +49,7 @@ final class StatusTableViewController: ChartsTableViewController { DispatchQueue.main.async { switch LoopDataManager.LoopUpdateContext(rawValue: context) { case .none, .bolus?: - self.refreshContext.update(with: .status) + self.refreshContext.formUnion([.status, .insulin]) case .preferences?: self.refreshContext.formUnion([.status, .targets]) case .carbs?: From b5f3f1e78b6e409e2d8b486d2ee5cefe68c14c4a Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sat, 2 Sep 2017 15:29:06 -0500 Subject: [PATCH 2/2] Improve tracking of recent boluses --- Loop/Extensions/NewPumpEvent.swift | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Loop/Extensions/NewPumpEvent.swift diff --git a/Loop/Extensions/NewPumpEvent.swift b/Loop/Extensions/NewPumpEvent.swift new file mode 100644 index 0000000000..14fec116f1 --- /dev/null +++ b/Loop/Extensions/NewPumpEvent.swift @@ -0,0 +1,29 @@ +// +// NewPumpEvent.swift +// Loop +// +// Copyright © 2017 LoopKit Authors. All rights reserved. +// + +import InsulinKit + + +extension NewPumpEvent { + + /// Constructs a pump event placeholder representing a bolus just enacted. + /// + /// - Parameters: + /// - units: The units of insulin requested + /// - date: The date the bolus was enacted + static func enactedBolus(units: Double, at date: Date) -> NewPumpEvent { + let dose = DoseEntry(type: .bolus, startDate: date, endDate: date, value: units, unit: .units) + + return self.init( + date: date, + dose: dose, + isMutable: true, + raw: Data(), // This can be empty, as mutable events aren't persisted + title: "" + ) + } +}