DeviceStatusTask.swift 985 B

1234567891011121314151617181920212223242526272829
  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. // No device-status source (e.g. Dexcom-only): drop any forecast left over
  16. // from a previous Loop/Trio source so it doesn't linger on the chart.
  17. clearLoopPredictionGraph()
  18. clearOpenAPSPredictionGraph()
  19. TaskScheduler.shared.rescheduleTask(id: .deviceStatus, to: Date().addingTimeInterval(60))
  20. return
  21. }
  22. webLoadNSDeviceStatus()
  23. }
  24. }