DeviceStatusTask.swift 765 B

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