FreeAPSSettings.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import Foundation
  2. struct FreeAPSSettings: JSON, Equatable {
  3. var units: GlucoseUnits = .mmolL
  4. var closedLoop: Bool = false
  5. var allowAnnouncements: Bool = false
  6. var useAutotune: Bool = false
  7. var isUploadEnabled: Bool = false
  8. var useLocalGlucoseSource: Bool = false
  9. var localGlucosePort: Int = 8080
  10. var debugOptions: Bool = false
  11. var insulinReqFraction: Decimal = 0.7
  12. var skipBolusScreenAfterCarbs: Bool = false
  13. var cgm: CGMType = .nightscout
  14. var uploadGlucose: Bool = false
  15. var useCalendar: Bool = false
  16. var glucoseBadge: Bool = false
  17. var glucoseNotifications: Bool = false
  18. }
  19. extension FreeAPSSettings: Decodable {
  20. // Needed to decode incomplete JSON
  21. init(from decoder: Decoder) throws {
  22. let container = try decoder.container(keyedBy: CodingKeys.self)
  23. var settings = FreeAPSSettings()
  24. if let units = try? container.decode(GlucoseUnits.self, forKey: .units) {
  25. settings.units = units
  26. }
  27. if let closedLoop = try? container.decode(Bool.self, forKey: .closedLoop) {
  28. settings.closedLoop = closedLoop
  29. }
  30. if let allowAnnouncements = try? container.decode(Bool.self, forKey: .allowAnnouncements) {
  31. settings.allowAnnouncements = allowAnnouncements
  32. }
  33. if let useAutotune = try? container.decode(Bool.self, forKey: .useAutotune) {
  34. settings.useAutotune = useAutotune
  35. }
  36. if let isUploadEnabled = try? container.decode(Bool.self, forKey: .isUploadEnabled) {
  37. settings.isUploadEnabled = isUploadEnabled
  38. }
  39. if let useLocalGlucoseSource = try? container.decode(Bool.self, forKey: .useLocalGlucoseSource) {
  40. settings.useLocalGlucoseSource = useLocalGlucoseSource
  41. }
  42. if let localGlucosePort = try? container.decode(Int.self, forKey: .localGlucosePort) {
  43. settings.localGlucosePort = localGlucosePort
  44. }
  45. if let debugOptions = try? container.decode(Bool.self, forKey: .debugOptions) {
  46. settings.debugOptions = debugOptions
  47. }
  48. if let insulinReqFraction = try? container.decode(Decimal.self, forKey: .insulinReqFraction) {
  49. settings.insulinReqFraction = insulinReqFraction
  50. }
  51. if let skipBolusScreenAfterCarbs = try? container.decode(Bool.self, forKey: .skipBolusScreenAfterCarbs) {
  52. settings.skipBolusScreenAfterCarbs = skipBolusScreenAfterCarbs
  53. }
  54. if let cgm = try? container.decode(CGMType.self, forKey: .cgm) {
  55. settings.cgm = cgm
  56. }
  57. if let uploadGlucose = try? container.decode(Bool.self, forKey: .uploadGlucose) {
  58. settings.uploadGlucose = uploadGlucose
  59. }
  60. if let useCalendar = try? container.decode(Bool.self, forKey: .useCalendar) {
  61. settings.useCalendar = useCalendar
  62. }
  63. if let glucoseBadge = try? container.decode(Bool.self, forKey: .glucoseBadge) {
  64. settings.glucoseBadge = glucoseBadge
  65. }
  66. if let glucoseNotifications = try? container.decode(Bool.self, forKey: .glucoseNotifications) {
  67. settings.glucoseNotifications = glucoseNotifications
  68. }
  69. self = settings
  70. }
  71. }