AlarmType.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // LoopFollow
  2. // AlarmType.swift
  3. import Foundation
  4. /// Categorizes alarms into distinct types, prioritized in the order they appear here.
  5. /// Multiple user-defined alarms may share the same type but differ in configuration.
  6. enum AlarmType: String, CaseIterable, Codable {
  7. case temporary = "Temporary Alert"
  8. case iob = "IOB Alert"
  9. case cob = "COB Alert"
  10. case low = "Low BG Alert"
  11. case high = "High BG Alert"
  12. case fastDrop = "Fast Drop Alert"
  13. case fastRise = "Fast Rise Alert"
  14. case missedReading = "Missed Reading Alert"
  15. case notLooping = "Not Looping Alert"
  16. case missedBolus = "Missed Bolus Alert"
  17. case futureCarbs = "Future Carbs Alert"
  18. case sensorChange = "Sensor Change Alert"
  19. case pumpChange = "Pump Change Alert"
  20. case pump = "Pump Insulin Alert"
  21. case pumpBattery = "Pump Battery Alert"
  22. case battery = "Low Battery"
  23. case batteryDrop = "Battery Drop"
  24. case recBolus = "Rec. Bolus"
  25. case overrideStart = "Override Started"
  26. case overrideEnd = "Override Ended"
  27. case tempTargetStart = "Temp Target Started"
  28. case tempTargetEnd = "Temp Target Ended"
  29. case buildExpire = "Looping app expiration"
  30. }
  31. extension AlarmType {
  32. var priority: Int {
  33. return AlarmType.allCases.firstIndex(of: self) ?? 0
  34. }
  35. }
  36. extension AlarmType {
  37. /// Localized, user-facing title. `rawValue` stays the stable identity/storage key
  38. /// (used for the alarm's default name and logs); this is only for display.
  39. var localizedTitle: String {
  40. String(localized: String.LocalizationValue(rawValue))
  41. }
  42. }
  43. extension AlarmType {
  44. /// `true` for alarms whose primary trigger is a blood-glucose value
  45. /// or its rate of change.
  46. var isBGBased: Bool {
  47. switch self {
  48. case .low, .high, .fastDrop, .fastRise, .missedReading, .temporary:
  49. return true
  50. default:
  51. return false
  52. }
  53. }
  54. }