TempBasalDurationPumpEvent.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // TempBasalDurationPumpEvent.swift
  3. // RileyLink
  4. //
  5. // Created by Pete Schwamb on 3/20/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct TempBasalDurationPumpEvent: TimestampedPumpEvent {
  10. public let length: Int
  11. public let rawData: Data
  12. public let duration: Int
  13. public let timestamp: DateComponents
  14. public init?(availableData: Data, pumpModel: PumpModel) {
  15. length = 7
  16. func d(_ idx: Int) -> Int {
  17. return Int(availableData[idx])
  18. }
  19. guard length <= availableData.count else {
  20. return nil
  21. }
  22. rawData = availableData.subdata(in: 0..<length)
  23. duration = d(1) * 30
  24. timestamp = DateComponents(pumpEventData: availableData, offset: 2)
  25. }
  26. public var dictionaryRepresentation: [String: Any] {
  27. return [
  28. "_type": "TempBasalDuration",
  29. "duration": duration,
  30. ]
  31. }
  32. public var description: String {
  33. return String(format: LocalizedString("Temporary Basal: %1$d min", comment: "The format string description of a TempBasalDurationPumpEvent. (1: The duration of the temp basal in minutes)"), duration)
  34. }
  35. }