TrioSettings.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. import Foundation
  2. enum BolusShortcutLimit: String, JSON, CaseIterable, Identifiable {
  3. var id: String { rawValue }
  4. case notAllowed
  5. case limitBolusMax
  6. var displayName: String {
  7. switch self {
  8. case .notAllowed:
  9. return String(localized: "Not allowed")
  10. case .limitBolusMax:
  11. return String(localized: "Max bolus")
  12. }
  13. }
  14. }
  15. struct TrioSettings: JSON, Equatable {
  16. var units: GlucoseUnits = .mgdL
  17. var closedLoop: Bool = false
  18. var isUploadEnabled: Bool = false
  19. var isDownloadEnabled: Bool = false
  20. var useLocalGlucoseSource: Bool = false
  21. var localGlucosePort: Int = 8080
  22. var debugOptions: Bool = false
  23. var cgm: CGMType = .none
  24. var cgmPluginIdentifier: String = ""
  25. var uploadGlucose: Bool = true
  26. var useCalendar: Bool = false
  27. var displayCalendarIOBandCOB: Bool = false
  28. var displayCalendarEmojis: Bool = false
  29. var glucoseBadge: Bool = false
  30. var notificationsPump: Bool = true
  31. var notificationsCgm: Bool = true
  32. var notificationsCarb: Bool = true
  33. var notificationsAlgorithm: Bool = true
  34. var glucoseNotificationsOption: GlucoseNotificationsOption = .onlyAlarmLimits
  35. var addSourceInfoToGlucoseNotifications: Bool = false
  36. var lowGlucose: Decimal = 72
  37. var highGlucose: Decimal = 270
  38. var carbsRequiredThreshold: Decimal = 10
  39. var showCarbsRequiredBadge: Bool = true
  40. var useFPUconversion: Bool = true
  41. var individualAdjustmentFactor: Decimal = 0.5
  42. var timeCap: Decimal = 8
  43. var minuteInterval: Decimal = 30
  44. var delay: Decimal = 60
  45. var useAppleHealth: Bool = false
  46. var smoothGlucose: Bool = false
  47. var eA1cDisplayUnit: EstimatedA1cDisplayUnit = .percent
  48. var high: Decimal = 180
  49. var low: Decimal = 70
  50. var hours: Int = 6
  51. var glucoseColorScheme: GlucoseColorScheme = .staticColor
  52. var xGridLines: Bool = true
  53. var yGridLines: Bool = true
  54. var rulerMarks: Bool = true
  55. var forecastDisplayType: ForecastDisplayType = .cone
  56. var maxCarbs: Decimal = 250
  57. var maxFat: Decimal = 250
  58. var maxProtein: Decimal = 250
  59. var confirmBolusFaster: Bool = false
  60. var overrideFactor: Decimal = 0.8
  61. var fattyMeals: Bool = false
  62. var fattyMealFactor: Decimal = 0.7
  63. var sweetMeals: Bool = false
  64. var sweetMealFactor: Decimal = 1
  65. var displayPresets: Bool = true
  66. var confirmBolus: Bool = false
  67. var useLiveActivity: Bool = false
  68. var lockScreenView: LockScreenView = .simple
  69. var bolusShortcut: BolusShortcutLimit = .notAllowed
  70. var timeInRangeType: TimeInRangeType = .timeInTightRange
  71. }
  72. extension TrioSettings: Decodable {
  73. // Needed to decode incomplete JSON
  74. init(from decoder: Decoder) throws {
  75. let container = try decoder.container(keyedBy: CodingKeys.self)
  76. var settings = TrioSettings()
  77. if let units = try? container.decode(GlucoseUnits.self, forKey: .units) {
  78. settings.units = units
  79. }
  80. if let closedLoop = try? container.decode(Bool.self, forKey: .closedLoop) {
  81. settings.closedLoop = closedLoop
  82. }
  83. if let isUploadEnabled = try? container.decode(Bool.self, forKey: .isUploadEnabled) {
  84. settings.isUploadEnabled = isUploadEnabled
  85. }
  86. if let isDownloadEnabled = try? container.decode(Bool.self, forKey: .isDownloadEnabled) {
  87. settings.isDownloadEnabled = isDownloadEnabled
  88. }
  89. if let useLocalGlucoseSource = try? container.decode(Bool.self, forKey: .useLocalGlucoseSource) {
  90. settings.useLocalGlucoseSource = useLocalGlucoseSource
  91. }
  92. if let localGlucosePort = try? container.decode(Int.self, forKey: .localGlucosePort) {
  93. settings.localGlucosePort = localGlucosePort
  94. }
  95. if let debugOptions = try? container.decode(Bool.self, forKey: .debugOptions) {
  96. settings.debugOptions = debugOptions
  97. }
  98. if let cgm = try? container.decode(CGMType.self, forKey: .cgm) {
  99. settings.cgm = cgm
  100. }
  101. if let cgmPluginIdentifier = try? container.decode(String.self, forKey: .cgmPluginIdentifier) {
  102. settings.cgmPluginIdentifier = cgmPluginIdentifier
  103. }
  104. if let uploadGlucose = try? container.decode(Bool.self, forKey: .uploadGlucose) {
  105. settings.uploadGlucose = uploadGlucose
  106. }
  107. if let useCalendar = try? container.decode(Bool.self, forKey: .useCalendar) {
  108. settings.useCalendar = useCalendar
  109. }
  110. if let displayCalendarIOBandCOB = try? container.decode(Bool.self, forKey: .displayCalendarIOBandCOB) {
  111. settings.displayCalendarIOBandCOB = displayCalendarIOBandCOB
  112. }
  113. if let displayCalendarEmojis = try? container.decode(Bool.self, forKey: .displayCalendarEmojis) {
  114. settings.displayCalendarEmojis = displayCalendarEmojis
  115. }
  116. if let useAppleHealth = try? container.decode(Bool.self, forKey: .useAppleHealth) {
  117. settings.useAppleHealth = useAppleHealth
  118. }
  119. if let glucoseBadge = try? container.decode(Bool.self, forKey: .glucoseBadge) {
  120. settings.glucoseBadge = glucoseBadge
  121. }
  122. if let useFPUconversion = try? container.decode(Bool.self, forKey: .useFPUconversion) {
  123. settings.useFPUconversion = useFPUconversion
  124. }
  125. if let individualAdjustmentFactor = try? container.decode(Decimal.self, forKey: .individualAdjustmentFactor) {
  126. settings.individualAdjustmentFactor = individualAdjustmentFactor
  127. }
  128. if let fattyMeals = try? container.decode(Bool.self, forKey: .fattyMeals) {
  129. settings.fattyMeals = fattyMeals
  130. }
  131. if let fattyMealFactor = try? container.decode(Decimal.self, forKey: .fattyMealFactor) {
  132. settings.fattyMealFactor = fattyMealFactor
  133. }
  134. if let sweetMeals = try? container.decode(Bool.self, forKey: .sweetMeals) {
  135. settings.sweetMeals = sweetMeals
  136. }
  137. if let sweetMealFactor = try? container.decode(Decimal.self, forKey: .sweetMealFactor) {
  138. settings.sweetMealFactor = sweetMealFactor
  139. }
  140. if let overrideFactor = try? container.decode(Decimal.self, forKey: .overrideFactor) {
  141. settings.overrideFactor = overrideFactor
  142. }
  143. if let timeCap = try? container.decode(Decimal.self, forKey: .timeCap) {
  144. settings.timeCap = timeCap
  145. }
  146. if let minuteInterval = try? container.decode(Decimal.self, forKey: .minuteInterval) {
  147. settings.minuteInterval = minuteInterval
  148. }
  149. if let delay = try? container.decode(Decimal.self, forKey: .delay) {
  150. settings.delay = delay
  151. }
  152. if let notificationsPump = try? container.decode(Bool.self, forKey: .notificationsPump) {
  153. settings.notificationsPump = notificationsPump
  154. }
  155. if let notificationsCgm = try? container.decode(Bool.self, forKey: .notificationsCgm) {
  156. settings.notificationsCgm = notificationsCgm
  157. }
  158. if let notificationsCarb = try? container.decode(Bool.self, forKey: .notificationsCarb) {
  159. settings.notificationsCarb = notificationsCarb
  160. }
  161. if let notificationsAlgorithm = try? container.decode(Bool.self, forKey: .notificationsAlgorithm) {
  162. settings.notificationsAlgorithm = notificationsAlgorithm
  163. }
  164. if let glucoseNotificationsOption = try? container.decode(
  165. GlucoseNotificationsOption.self,
  166. forKey: .glucoseNotificationsOption
  167. ) {
  168. settings.glucoseNotificationsOption = glucoseNotificationsOption
  169. }
  170. if let addSourceInfoToGlucoseNotifications = try? container.decode(
  171. Bool.self,
  172. forKey: .addSourceInfoToGlucoseNotifications
  173. ) {
  174. settings.addSourceInfoToGlucoseNotifications = addSourceInfoToGlucoseNotifications
  175. }
  176. if let lowGlucose = try? container.decode(Decimal.self, forKey: .lowGlucose) {
  177. settings.lowGlucose = lowGlucose
  178. }
  179. if let highGlucose = try? container.decode(Decimal.self, forKey: .highGlucose) {
  180. settings.highGlucose = highGlucose
  181. }
  182. if let carbsRequiredThreshold = try? container.decode(Decimal.self, forKey: .carbsRequiredThreshold) {
  183. settings.carbsRequiredThreshold = carbsRequiredThreshold
  184. }
  185. if let showCarbsRequiredBadge = try? container.decode(Bool.self, forKey: .showCarbsRequiredBadge) {
  186. settings.showCarbsRequiredBadge = showCarbsRequiredBadge
  187. }
  188. if let smoothGlucose = try? container.decode(Bool.self, forKey: .smoothGlucose) {
  189. settings.smoothGlucose = smoothGlucose
  190. }
  191. if let low = try? container.decode(Decimal.self, forKey: .low) {
  192. settings.low = low
  193. }
  194. if let high = try? container.decode(Decimal.self, forKey: .high) {
  195. settings.high = high
  196. }
  197. if let hours = try? container.decode(Int.self, forKey: .hours) {
  198. settings.hours = hours
  199. }
  200. if let glucoseColorScheme = try? container.decode(GlucoseColorScheme.self, forKey: .glucoseColorScheme) {
  201. settings.glucoseColorScheme = glucoseColorScheme
  202. }
  203. if let xGridLines = try? container.decode(Bool.self, forKey: .xGridLines) {
  204. settings.xGridLines = xGridLines
  205. }
  206. if let yGridLines = try? container.decode(Bool.self, forKey: .yGridLines) {
  207. settings.yGridLines = yGridLines
  208. }
  209. if let rulerMarks = try? container.decode(Bool.self, forKey: .rulerMarks) {
  210. settings.rulerMarks = rulerMarks
  211. }
  212. if let forecastDisplayType = try? container.decode(ForecastDisplayType.self, forKey: .forecastDisplayType) {
  213. settings.forecastDisplayType = forecastDisplayType
  214. }
  215. if let eA1cDisplayUnit = try? container.decode(EstimatedA1cDisplayUnit.self, forKey: .eA1cDisplayUnit) {
  216. settings.eA1cDisplayUnit = eA1cDisplayUnit
  217. }
  218. if let maxCarbs = try? container.decode(Decimal.self, forKey: .maxCarbs) {
  219. settings.maxCarbs = maxCarbs
  220. }
  221. if let maxFat = try? container.decode(Decimal.self, forKey: .maxFat) {
  222. settings.maxFat = maxFat
  223. }
  224. if let maxProtein = try? container.decode(Decimal.self, forKey: .maxProtein) {
  225. settings.maxProtein = maxProtein
  226. }
  227. if let confirmBolusFaster = try? container.decode(Bool.self, forKey: .confirmBolusFaster) {
  228. settings.confirmBolusFaster = confirmBolusFaster
  229. }
  230. if let displayPresets = try? container.decode(Bool.self, forKey: .displayPresets) {
  231. settings.displayPresets = displayPresets
  232. }
  233. if let confirmBolus = try? container.decode(Bool.self, forKey: .confirmBolus) {
  234. settings.confirmBolus = confirmBolus
  235. }
  236. if let useLiveActivity = try? container.decode(Bool.self, forKey: .useLiveActivity) {
  237. settings.useLiveActivity = useLiveActivity
  238. }
  239. if let lockScreenView = try? container.decode(LockScreenView.self, forKey: .lockScreenView) {
  240. settings.lockScreenView = lockScreenView
  241. }
  242. if let bolusShortcut = try? container.decode(BolusShortcutLimit.self, forKey: .bolusShortcut) {
  243. settings.bolusShortcut = bolusShortcut
  244. }
  245. if let timeInRangeType = try? container.decode(TimeInRangeType.self, forKey: .timeInRangeType) {
  246. settings.timeInRangeType = timeInRangeType
  247. }
  248. self = settings
  249. }
  250. }