Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion LoopKit/InsulinKit/PumpEventType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum PumpEventType: CaseIterable, Equatable {
}
}

var rawValue: String {
public var rawValue: String {
switch self {
case .alarm:
return "AlarmPump"
Expand Down
8 changes: 8 additions & 0 deletions MockKit/MockPumpManagerState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()),
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -347,6 +351,10 @@ extension MockPumpManagerState: RawRepresentable {
if deliveryCommandsShouldTriggerUncertainDelivery {
raw["deliveryCommandsShouldTriggerUncertainDelivery"] = true
}

if replacePumpComponent {
raw["replacePumpComponent"] = true
}

if deliveryIsUncertain {
raw["deliveryIsUncertain"] = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ final class MockPumpManagerSettingsViewController: UITableViewController {
case suspendResume = 0
case occlusion
case pumpError
case pumpComponentReplacement
}

private enum SettingsRow: Int, CaseIterable {
Expand Down Expand Up @@ -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)! {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}