Glucose+SensorDisplayable.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // GlucoseRxMessage.swift
  3. // Loop
  4. //
  5. // Created by Nathan Racklyeft on 5/30/16.
  6. // Copyright © 2016 Nathan Racklyeft. All rights reserved.
  7. //
  8. import Foundation
  9. extension Glucose {
  10. public var isStateValid: Bool {
  11. return state == .known(.ok) && status == .ok
  12. }
  13. public var stateDescription: String {
  14. var messages = [String]()
  15. switch state {
  16. case .known(.ok):
  17. break // Suppress the "OK" message
  18. default:
  19. messages.append(state.localizedDescription)
  20. }
  21. switch self.status {
  22. case .ok:
  23. if messages.isEmpty {
  24. messages.append(status.localizedDescription)
  25. } else {
  26. break // Suppress the "OK" message
  27. }
  28. case .lowBattery, .unknown:
  29. messages.append(status.localizedDescription)
  30. }
  31. return messages.joined(separator: ". ")
  32. }
  33. // public var trendType: GlucoseTrend? {
  34. // guard trend < Int(Int8.max) else {
  35. // return nil
  36. // }
  37. //
  38. // switch trend {
  39. // case let x where x <= -30:
  40. // return .downDownDown
  41. // case let x where x <= -20:
  42. // return .downDown
  43. // case let x where x <= -10:
  44. // return .down
  45. // case let x where x < 10:
  46. // return .flat
  47. // case let x where x < 20:
  48. // return .up
  49. // case let x where x < 30:
  50. // return .upUp
  51. // default:
  52. // return .upUpUp
  53. // }
  54. // }
  55. public var isLocal: Bool {
  56. return true
  57. }
  58. }