DeliveryLimits.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // DeliveryLimits.swift
  3. // LoopKit
  4. //
  5. // Created by Rick Pasetto on 7/15/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import HealthKit
  9. public struct DeliveryLimits: Equatable {
  10. public enum Setting: Equatable {
  11. case maximumBasalRate
  12. case maximumBolus
  13. }
  14. private var settings: [Setting: HKQuantity]
  15. public init(maximumBasalRate: HKQuantity?, maximumBolus: HKQuantity?) {
  16. settings = [:]
  17. settings[.maximumBasalRate] = maximumBasalRate
  18. settings[.maximumBolus] = maximumBolus
  19. }
  20. public var maximumBasalRate: HKQuantity? {
  21. get { settings[.maximumBasalRate] }
  22. set { settings[.maximumBasalRate] = newValue }
  23. }
  24. public var maximumBolus: HKQuantity? {
  25. get { settings[.maximumBolus] }
  26. set { settings[.maximumBolus] = newValue }
  27. }
  28. }
  29. public extension DeliveryLimits.Setting {
  30. // The following comes from https://tidepool.atlassian.net/browse/IFU-24
  31. var title: String {
  32. switch self {
  33. case .maximumBasalRate:
  34. return LocalizedString("Maximum Basal Rate", comment: "Title text for maximum basal rate configuration")
  35. case .maximumBolus:
  36. return LocalizedString("Maximum Bolus", comment: "Title text for maximum bolus configuration")
  37. }
  38. }
  39. func localizedDescriptiveText(appName: String) -> String {
  40. switch self {
  41. case .maximumBasalRate:
  42. return String(format: LocalizedString("Maximum Basal Rate is the highest temporary basal rate %1$@ is allowed to set.", comment: "Descriptive text for maximum basal rate (1: app name)"), appName)
  43. case .maximumBolus:
  44. return LocalizedString("Maximum Bolus is the highest bolus amount you can deliver at one time to cover carbs or bring down high glucose.", comment: "Descriptive text for maximum bolus")
  45. }
  46. }
  47. }