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/DoseType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension DoseType {
self = .suspend
case .tempBasal:
self = .tempBasal
case .alarm, .alarmClear, .prime, .rewind:
case .alarm, .alarmClear, .prime, .rewind, .replaceComponent:
return nil
}
}
Expand Down
95 changes: 84 additions & 11 deletions LoopKit/InsulinKit/PumpEventType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,86 @@
import Foundation


/// A subset of pump event types, with raw values matching decocare's strings
public enum PumpEventType: String, CaseIterable {
case alarm = "AlarmPump"
case alarmClear = "ClearAlarm"
case basal = "BasalProfileStart"
case bolus = "Bolus"
case prime = "Prime"
case resume = "PumpResume"
case rewind = "Rewind"
case suspend = "PumpSuspend"
case tempBasal = "TempBasal"
/// A subset of pump event types
public enum PumpEventType: CaseIterable, Equatable {
typealias RawValue = String

case alarm
case alarmClear
case basal
case bolus
case prime
case resume
case rewind
case suspend
case tempBasal
case replaceComponent(componentType: ReplaceableComponent)

init?(rawValue: String) {
switch rawValue {
case "AlarmPump":
self = .alarm
case "ClearAlarm":
self = .alarmClear
case "BasalProfileStart":
self = .basal
case "Bolus":
self = .bolus
case "Prime":
self = .prime
case "PumpResume":
self = .resume
case "Rewind":
self = .rewind
case "PumpSuspend":
self = .suspend
case "TempBasal":
self = .tempBasal
default:
if rawValue.starts(with: "Replace"), let value = ReplaceableComponent(rawValue: String(rawValue.dropFirst(7))) {
self = .replaceComponent(componentType: value)
} else {
return nil
}
}
}

var rawValue: String {
switch self {
case .alarm:
return "AlarmPump"
case .alarmClear:
return "ClearAlarm"
case .basal:
return "BasalProfileStart"
case .bolus:
return "Bolus"
case .prime:
return "Prime"
case .resume:
return "PumpResume"
case .rewind:
return "Rewind"
case .suspend:
return "PumpSuspend"
case .tempBasal:
return "TempBasal"
case let .replaceComponent(componentType):
return "Replace\(componentType.rawValue)"
}
}

public static var allCases: [PumpEventType] {
return [.alarm, .alarmClear, .basal, .bolus, .prime, .resume, .rewind, .suspend, .tempBasal, .replaceComponent(componentType: .reservoir), .replaceComponent(componentType: .pump), .replaceComponent(componentType: .infusionSet)]
}
}

/// A subset of replaceable component types
public enum ReplaceableComponent: String {
case reservoir
case pump // Base, pod or patch full replacement
case infusionSet
}

extension PumpEventType {
/// Provides an ordering between types used for stable, chronological sorting for doses that share the same date.
Expand Down Expand Up @@ -50,6 +117,12 @@ extension PumpEventType {
return 8
case .basal:
return 9
case .replaceComponent(componentType: .reservoir):
return 10
case .replaceComponent(componentType: .pump):
return 11
case .replaceComponent(componentType: .infusionSet):
return 12
}
}
}