NewPumpEvent.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // NewPumpEvent.swift
  3. // LoopKit
  4. //
  5. // Created by Nate Racklyeft on 8/1/16.
  6. // Copyright © 2016 Nathan Racklyeft. All rights reserved.
  7. //
  8. import Foundation
  9. public struct NewPumpEvent {
  10. /// The date of the event
  11. public let date: Date
  12. /// The insulin dose described by the event, if applicable
  13. public let dose: DoseEntry?
  14. /// Whether the dose value is expected to change.
  15. public let isMutable: Bool
  16. /// The opaque raw data representing the event
  17. public let raw: Data
  18. /// The type of pump event
  19. public let type: PumpEventType?
  20. /// A human-readable title to describe the event
  21. public let title: String
  22. public init(date: Date, dose: DoseEntry?, isMutable: Bool, raw: Data, title: String, type: PumpEventType? = nil) {
  23. self.date = date
  24. self.isMutable = isMutable
  25. self.raw = raw
  26. self.title = title
  27. var dose = dose
  28. // Use the raw data as the unique identifier for the dose
  29. dose?.syncIdentifier = raw.hexadecimalString
  30. self.dose = dose
  31. // Try to use the dose's type if no explicit type was set
  32. self.type = type ?? dose?.type.pumpEventType
  33. }
  34. }