From 437addf7837f097dd485b59967a84ae32ba7e24a Mon Sep 17 00:00:00 2001 From: Arwain Date: Tue, 22 Aug 2023 13:42:05 -1000 Subject: [PATCH] Logic to capture reservoir changes --- LoopKit/InsulinKit/PumpEventType.swift | 2 +- MockKit/MockPumpManagerState.swift | 8 +++++++ ...ockPumpManagerSettingsViewController.swift | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/LoopKit/InsulinKit/PumpEventType.swift b/LoopKit/InsulinKit/PumpEventType.swift index e058732ae..63630ef43 100644 --- a/LoopKit/InsulinKit/PumpEventType.swift +++ b/LoopKit/InsulinKit/PumpEventType.swift @@ -53,7 +53,7 @@ public enum PumpEventType: CaseIterable, Equatable { } } - var rawValue: String { + public var rawValue: String { switch self { case .alarm: return "AlarmPump" diff --git a/MockKit/MockPumpManagerState.swift b/MockKit/MockPumpManagerState.swift index b45267f3d..ddb662fcc 100644 --- a/MockKit/MockPumpManagerState.swift +++ b/MockKit/MockPumpManagerState.swift @@ -145,6 +145,7 @@ public struct MockPumpManagerState: Equatable { public var bolusShouldCrash: Bool public var tempBasalShouldCrash: Bool public var deliveryCommandsShouldTriggerUncertainDelivery: Bool + public var replacePumpComponent: Bool public var maximumBolus: Double public var maximumBasalRatePerHour: Double public var suspendState: SuspendState @@ -184,6 +185,7 @@ public struct MockPumpManagerState: Equatable { bolusShouldCrash: Bool = false, tempBasalShouldCrash: Bool = false, deliveryCommandsShouldTriggerUncertainDelivery: Bool = false, + replacePumpComponent: Bool = false, maximumBolus: Double = 25.0, maximumBasalRatePerHour: Double = 5.0, suspendState: SuspendState = .resumed(Date()), @@ -208,6 +210,7 @@ public struct MockPumpManagerState: Equatable { self.bolusShouldCrash = bolusShouldCrash self.tempBasalShouldCrash = tempBasalShouldCrash self.deliveryCommandsShouldTriggerUncertainDelivery = deliveryCommandsShouldTriggerUncertainDelivery + self.replacePumpComponent = replacePumpComponent self.maximumBolus = maximumBolus self.maximumBasalRatePerHour = maximumBasalRatePerHour self.suspendState = suspendState @@ -255,6 +258,7 @@ extension MockPumpManagerState: RawRepresentable { self.bolusShouldCrash = rawValue["bolusShouldCrash"] as? Bool ?? false self.tempBasalShouldCrash = rawValue["tempBasalShouldCrash"] as? Bool ?? false self.deliveryCommandsShouldTriggerUncertainDelivery = rawValue["deliveryCommandsShouldTriggerUncertainDelivery"] as? Bool ?? false + self.replacePumpComponent = rawValue["replacePumpComponent"] as? Bool ?? false self.maximumBolus = rawValue["maximumBolus"] as? Double ?? 25.0 self.maximumBasalRatePerHour = rawValue["maximumBasalRatePerHour"] as? Double ?? 5.0 self.pumpBatteryChargeRemaining = rawValue["pumpBatteryChargeRemaining"] as? Double ?? nil @@ -347,6 +351,10 @@ extension MockPumpManagerState: RawRepresentable { if deliveryCommandsShouldTriggerUncertainDelivery { raw["deliveryCommandsShouldTriggerUncertainDelivery"] = true } + + if replacePumpComponent { + raw["replacePumpComponent"] = true + } if deliveryIsUncertain { raw["deliveryIsUncertain"] = true diff --git a/MockKitUI/View Controllers/MockPumpManagerSettingsViewController.swift b/MockKitUI/View Controllers/MockPumpManagerSettingsViewController.swift index d0df518a0..3c76c53c5 100644 --- a/MockKitUI/View Controllers/MockPumpManagerSettingsViewController.swift +++ b/MockKitUI/View Controllers/MockPumpManagerSettingsViewController.swift @@ -79,6 +79,7 @@ final class MockPumpManagerSettingsViewController: UITableViewController { case suspendResume = 0 case occlusion case pumpError + case pumpComponentReplacement } private enum SettingsRow: Int, CaseIterable { @@ -175,6 +176,14 @@ final class MockPumpManagerSettingsViewController: UITableViewController { cell.textLabel?.text = "Cause Pump Error" } return cell + case .pumpComponentReplacement: + let cell = tableView.dequeueReusableCell(withIdentifier: TextButtonTableViewCell.className, for: indexPath) as! TextButtonTableViewCell + if pumpManager.state.replacePumpComponent { + cell.textLabel?.text = "Resume Therapy" + } else { + cell.textLabel?.text = "Replace Pump Component" + } + return cell } case .settings: switch SettingsRow(rawValue: indexPath.row)! { @@ -339,6 +348,11 @@ final class MockPumpManagerSettingsViewController: UITableViewController { pumpManager.state.pumpErrorDetected = !pumpManager.state.pumpErrorDetected tableView.deselectRow(at: indexPath, animated: true) tableView.reloadRows(at: [indexPath], with: .automatic) + case .pumpComponentReplacement: + pumpManager.injectPumpEvents(pumpManager.state.replacePumpComponent ? [NewPumpEvent(type: .replaceComponent(componentType: .pump))] : [NewPumpEvent(type: .replaceComponent(componentType: .pump))]) + pumpManager.state.replacePumpComponent = !pumpManager.state.replacePumpComponent + tableView.deselectRow(at: indexPath, animated: true) + tableView.reloadRows(at: [indexPath], with: .automatic) } case .settings: tableView.deselectRow(at: indexPath, animated: true) @@ -630,4 +644,12 @@ fileprivate extension NewPumpEvent { title: "alarmClear", type: .alarmClear) } + + init(type: PumpEventType) { + self.init(date: Date(), + dose: nil, + raw: Data(UUID().uuidString.utf8), + title: "type[\(type.rawValue)]", + type: type) + } }