BackgroundRefreshType.swift 2.0 KB

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