DeviceStatusTask.swift 734 B

12345678910111213141516171819202122232425
  1. // LoopFollow
  2. // DeviceStatusTask.swift
  3. import Foundation
  4. extension MainViewController {
  5. func scheduleDeviceStatusTask(initialDelay: TimeInterval = 4) {
  6. let startTime = Date().addingTimeInterval(initialDelay)
  7. TaskScheduler.shared.scheduleTask(id: .deviceStatus, nextRun: startTime) { [weak self] in
  8. guard let self = self else { return }
  9. self.deviceStatusAction()
  10. }
  11. }
  12. func deviceStatusAction() {
  13. // If no NS config, we wait 60s before trying again:
  14. guard IsNightscoutEnabled() else {
  15. TaskScheduler.shared.rescheduleTask(id: .deviceStatus, to: Date().addingTimeInterval(60))
  16. return
  17. }
  18. webLoadNSDeviceStatus()
  19. }
  20. }