PumpStatus.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // PumpStatus.swift
  3. // RileyLink
  4. //
  5. // Created by Pete Schwamb on 7/26/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct PumpStatus {
  10. let clock: Date
  11. let pumpID: String
  12. let manufacturer: String?
  13. let model: String?
  14. let iob: IOBStatus?
  15. let battery: BatteryStatus?
  16. let suspended: Bool?
  17. let bolusing: Bool?
  18. let reservoir: Double?
  19. let secondsFromGMT: Int?
  20. public init(clock: Date, pumpID: String, manufacturer: String? = nil, model: String? = nil, iob: IOBStatus? = nil, battery: BatteryStatus? = nil, suspended: Bool? = nil, bolusing: Bool? = nil, reservoir: Double? = nil, secondsFromGMT: Int? = nil) {
  21. self.clock = clock
  22. self.pumpID = pumpID
  23. self.manufacturer = manufacturer
  24. self.model = model
  25. self.iob = iob
  26. self.battery = battery
  27. self.suspended = suspended
  28. self.bolusing = bolusing
  29. self.reservoir = reservoir
  30. self.secondsFromGMT = secondsFromGMT
  31. }
  32. public var dictionaryRepresentation: [String: Any] {
  33. var rval = [String: Any]()
  34. rval["clock"] = TimeFormat.timestampStrFromDate(clock)
  35. rval["pumpID"] = pumpID
  36. if let manufacturer = manufacturer {
  37. rval["manufacturer"] = manufacturer
  38. }
  39. if let model = model {
  40. rval["model"] = model
  41. }
  42. if let iob = iob {
  43. rval["iob"] = iob.dictionaryRepresentation
  44. }
  45. if let battery = battery {
  46. rval["battery"] = battery.dictionaryRepresentation
  47. }
  48. if let suspended = suspended {
  49. rval["suspended"] = suspended
  50. }
  51. if let bolusing = bolusing {
  52. rval["bolusing"] = bolusing
  53. }
  54. if let reservoir = reservoir {
  55. rval["reservoir"] = reservoir
  56. }
  57. if let secondsFromGMT = secondsFromGMT {
  58. rval["secondsFromGMT"] = secondsFromGMT
  59. }
  60. return rval
  61. }
  62. }