ChangeSensorSetup2PumpEvent.swift 892 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // ChangeSensorSetup2PumpEvent.swift
  3. // RileyLink
  4. //
  5. // Created by Pete Schwamb on 3/8/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct ChangeSensorSetup2PumpEvent: TimestampedPumpEvent {
  10. public let length: Int
  11. public let rawData: Data
  12. public let timestamp: DateComponents
  13. public init?(availableData: Data, pumpModel: PumpModel) {
  14. if pumpModel.hasLowSuspend {
  15. length = 41
  16. } else {
  17. length = 37
  18. }
  19. guard length <= availableData.count else {
  20. return nil
  21. }
  22. rawData = availableData.subdata(in: 0..<length)
  23. timestamp = DateComponents(pumpEventData: availableData, offset: 2)
  24. }
  25. public var dictionaryRepresentation: [String: Any] {
  26. return [
  27. "_type": "ChangeSensorSetup2",
  28. ]
  29. }
  30. }