DailyTotal523PumpEvent.swift 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // DailyTotal523PumpEvent.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 DailyTotal523PumpEvent: PumpEvent {
  10. public let length: Int
  11. public let rawData: Data
  12. public let timestamp: DateComponents
  13. public init?(availableData: Data, pumpModel: PumpModel) {
  14. length = 52
  15. // Sometimes we encounter this at the end of a page, and it can be less characters???
  16. // need at least 16, I think.
  17. guard 16 <= availableData.count else {
  18. return nil
  19. }
  20. rawData = availableData.subdata(in: 0..<min(length, availableData.count))
  21. timestamp = DateComponents(pumpEventBytes: availableData.subdata(in: 1..<3))
  22. }
  23. public var dictionaryRepresentation: [String: Any] {
  24. return [
  25. "_type": "DailyTotal523",
  26. "validDate": String(format: "%04d-%02d-%02d", timestamp.year!, timestamp.month!, timestamp.day!),
  27. ]
  28. }
  29. }