Quellcode durchsuchen

Modified Not Looping handling

Jonas Björkert vor 1 Jahr
Ursprung
Commit
b1bec482b4

+ 7 - 4
LoopFollow/Controllers/Nightscout/DeviceStatus.swift

@@ -34,11 +34,13 @@ extension MainViewController {
         DispatchQueue.main.async {
             TaskScheduler.shared.rescheduleTask(id: .deviceStatus, to: Date().addingTimeInterval(10))
         }
+
+        evaluateNotLooping()
     }
     
-    func evaluateNotLooping(lastLoopTime: TimeInterval) {
+    func evaluateNotLooping() {
         if let statusStackView = LoopStatusLabel.superview as? UIStackView {
-            if ((TimeInterval(Date().timeIntervalSince1970) - lastLoopTime) / 60) > 15 {
+            if ((TimeInterval(Date().timeIntervalSince1970) - UserDefaultsRepository.alertLastLoopTime.value) / 60) > 15 {
                 IsNotLooping = true
                 // Change the distribution to 'fill' to allow manual resizing of arranged subviews
                 statusStackView.distribution = .fill
@@ -70,7 +72,6 @@ extension MainViewController {
                 }
             }
         }
-        latestLoopTime = lastLoopTime
     }
         
     // NS Device Status Response Processor
@@ -145,7 +146,7 @@ extension MainViewController {
 
         // Start the timer based on the timestamp
         let now = dateTimeUtils.getNowTimeIntervalUTC()
-        let secondsAgo = now - latestLoopTime
+        let secondsAgo = now - UserDefaultsRepository.alertLastLoopTime.value
         
         DispatchQueue.main.async {
             if secondsAgo >= (20 * 60) {
@@ -179,6 +180,8 @@ extension MainViewController {
                 )
             }
         }
+
+        evaluateNotLooping()
         LogManager.shared.log(category: .deviceStatus, message: "Update Device Status done", isDebug: true)
     }
 }

+ 2 - 3
LoopFollow/Controllers/Nightscout/DeviceStatusLoop.swift

@@ -15,6 +15,7 @@ extension MainViewController {
     func DeviceStatusLoop(formatter: ISO8601DateFormatter, lastLoopRecord: [String: AnyObject]) {
         ObservableUserDefaults.shared.device.value = "Loop"
         if let lastLoopTime = formatter.date(from: (lastLoopRecord["timestamp"] as! String))?.timeIntervalSince1970  {
+            let previousLastLoopTime = UserDefaultsRepository.alertLastLoopTime.value
             UserDefaultsRepository.alertLastLoopTime.value = lastLoopTime
             if let failure = lastLoopRecord["failureReason"] {
                 LoopStatusLabel.text = "X"
@@ -66,7 +67,7 @@ extension MainViewController {
                     let prediction = predictdata["values"] as! [Double]
                     PredictionLabel.text = Localizer.toDisplayUnits(String(Int(prediction.last!)))
                     PredictionLabel.textColor = UIColor.systemPurple
-                    if UserDefaultsRepository.downloadPrediction.value && latestLoopTime < lastLoopTime {
+                    if UserDefaultsRepository.downloadPrediction.value && previousLastLoopTime < lastLoopTime {
                         predictionData.removeAll()
                         var predictionTime = lastLoopTime
                         let toLoad = Int(UserDefaultsRepository.predictionToLoad.value * 12)
@@ -123,8 +124,6 @@ extension MainViewController {
                 }
                 
             }
-            
-            evaluateNotLooping(lastLoopTime: lastLoopTime)
         }
     }
 }

+ 0 - 4
LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift

@@ -13,12 +13,10 @@ extension MainViewController {
         if lastLoopRecord["failureReason"] != nil {
             LoopStatusLabel.text = "X"
             latestLoopStatusString = "X"
-            evaluateNotLooping(lastLoopTime: UserDefaultsRepository.alertLastLoopTime.value)
         } else {
             guard let enactedOrSuggested = lastLoopRecord["suggested"] as? [String: AnyObject] ?? lastLoopRecord["enacted"] as? [String: AnyObject] else {
                 LoopStatusLabel.text = "↻"
                 latestLoopStatusString = "↻"
-                evaluateNotLooping(lastLoopTime: UserDefaultsRepository.alertLastLoopTime.value)
                 return
             }
 
@@ -34,8 +32,6 @@ extension MainViewController {
                 wasEnacted = false
                 LogManager.shared.log(category: .deviceStatus, message: "Last devicestatus is missing enacted")
             }
-            evaluateNotLooping(lastLoopTime: UserDefaultsRepository.alertLastLoopTime.value)
-
 
             var updatedTime: TimeInterval?
 

+ 0 - 1
LoopFollow/ViewControllers/MainViewController.swift

@@ -108,7 +108,6 @@ class MainViewController: UIViewController, UITableViewDataSource, ChartViewDele
     var latestMinAgoString = ""
     var latestDeltaString = ""
     var latestLoopStatusString = ""
-    var latestLoopTime: Double = 0
     var latestCOB: CarbMetric?
     var latestBasal = ""
     var latestPumpVolume: Double = 50.0