BackgroundRefreshType.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // actual DASH or rPi DASH simulator
  57. return name == "TWI BOARD" || name == " :: Fake POD ::"
  58. }
  59. return false
  60. case .silentTune, .none:
  61. return false
  62. }
  63. }
  64. }