MySentryPumpStatusMessageBody+CGMManager.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // MySentryPumpStatusMessageBody.swift
  3. // Loop
  4. //
  5. // Created by Nate Racklyeft on 7/28/16.
  6. // Copyright © 2016 Nathan Racklyeft. All rights reserved.
  7. //
  8. import HealthKit
  9. import LoopKit
  10. extension MySentryPumpStatusMessageBody: GlucoseDisplayable {
  11. public var isStateValid: Bool {
  12. switch glucose {
  13. case .active:
  14. return true
  15. default:
  16. return false
  17. }
  18. }
  19. public var trendType: LoopKit.GlucoseTrend? {
  20. guard case .active = glucose else {
  21. return nil
  22. }
  23. switch glucoseTrend {
  24. case .down:
  25. return .down
  26. case .downDown:
  27. return .downDown
  28. case .up:
  29. return .up
  30. case .upUp:
  31. return .upUp
  32. case .flat:
  33. return .flat
  34. }
  35. }
  36. public var trendRate: HKQuantity? {
  37. return nil
  38. }
  39. public var isLocal: Bool {
  40. return true
  41. }
  42. // TODO Placeholder. This functionality will come with LOOP-1311
  43. public var glucoseRangeCategory: GlucoseRangeCategory? {
  44. return nil
  45. }
  46. var batteryPercentage: Int {
  47. return batteryRemainingPercent
  48. }
  49. var glucoseSyncIdentifier: String? {
  50. guard let date = glucoseDateComponents,
  51. let year = date.year,
  52. let month = date.month,
  53. let day = date.day,
  54. let hour = date.hour,
  55. let minute = date.minute,
  56. let second = date.second
  57. else {
  58. return nil
  59. }
  60. return "\(year)-\(month)-\(day) \(hour)-\(minute)-\(second)"
  61. }
  62. }