BackgroundRefreshType.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // LoopFollow
  2. // BackgroundRefreshType.swift
  3. import Foundation
  4. enum BackgroundRefreshType: String, Codable, CaseIterable {
  5. case none = "None"
  6. case silentTune = "Silent Tune"
  7. case rileyLink = "RileyLink"
  8. case dexcom = "Dexcom"
  9. case omnipodDash = "Omnipod Dash"
  10. /// Indicates if the device type uses Bluetooth
  11. var isBluetooth: Bool {
  12. switch self {
  13. case .rileyLink, .dexcom, .omnipodDash:
  14. return true
  15. case .silentTune, .none:
  16. return false
  17. }
  18. }
  19. var heartBeatInterval: TimeInterval? {
  20. switch self {
  21. case .rileyLink:
  22. return 60
  23. case .omnipodDash:
  24. return 3 * 60
  25. case .dexcom:
  26. return 5 * 60
  27. case .silentTune, .none:
  28. return nil
  29. }
  30. }
  31. var estimatedDelayBasedOnHeartbeat: Bool {
  32. switch self {
  33. case .rileyLink:
  34. return true
  35. case .dexcom, .omnipodDash, .silentTune, .none:
  36. return false
  37. }
  38. }
  39. /// Determines if a BLEDevice matches the specific device type
  40. func matches(_ device: BLEDevice) -> Bool {
  41. switch self {
  42. case .rileyLink:
  43. let rileyUUIDString = "0235733b-99c5-4197-b856-69219c2a3845"
  44. if let services = device.advertisedServices {
  45. return services.map { $0.lowercased() }
  46. .contains(rileyUUIDString.lowercased())
  47. }
  48. return false
  49. case .dexcom:
  50. if let name = device.name {
  51. return name.hasPrefix("DXCM") || name.hasPrefix("DX02") || name.hasPrefix("Dexcom")
  52. }
  53. return false
  54. case .omnipodDash:
  55. if let name = device.name {
  56. // "TWI BOARD": original DASH pod
  57. // "InPlay BLE": newer Atlas DASH pod
  58. // " :: Fake POD ::": rPi DASH simulator
  59. return name == "TWI BOARD" || name == "InPlay BLE" || name == " :: Fake POD ::"
  60. }
  61. return false
  62. case .silentTune, .none:
  63. return false
  64. }
  65. }
  66. }