File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ struct NotLoopingCondition: AlarmCondition {
88 static let type : AlarmType = . notLooping
99 init ( ) { }
1010
11- func evaluate( alarm: Alarm , data: AlarmData , now _ : Date ) -> Bool {
11+ func evaluate( alarm: Alarm , data: AlarmData , now: Date ) -> Bool {
1212 // ────────────────────────────────
1313 // 0. sanity checks
1414 // ────────────────────────────────
@@ -19,6 +19,17 @@ struct NotLoopingCondition: AlarmCondition {
1919 guard let lastLoopTime = data. lastLoopTime,
2020 lastLoopTime > 0 else { return false }
2121
22+ guard let lastChecked = Storage . shared. lastLoopingChecked. value else {
23+ // Never checked, so don't alarm.
24+ return false
25+ }
26+
27+ let checkedAgeSeconds = now. timeIntervalSince ( lastChecked)
28+ if checkedAgeSeconds > 360 { // 6 minutes
29+ // The check itself is stale, so the data is unreliable. Don't alarm.
30+ return false
31+ }
32+
2233 // ────────────────────────────────
2334 // 1. elapsed-time test
2435 // ────────────────────────────────
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ import UIKit
88
99extension MainViewController {
1010 func webLoadNSDeviceStatus( ) {
11+ Storage . shared. lastLoopingChecked. value = Date ( )
12+
1113 let parameters = [ " count " : " 1 " ]
1214 NightscoutUtils . executeDynamicRequest ( eventType: . deviceStatus, parameters: parameters) { result in
1315 switch result {
Original file line number Diff line number Diff line change @@ -160,6 +160,8 @@ class Storage {
160160 var persistentNotification = StorageValue < Bool > ( key: " persistentNotification " , defaultValue: false )
161161 var persistentNotificationLastBGTime = StorageValue < Date > ( key: " persistentNotificationLastBGTime " , defaultValue: . distantPast)
162162
163+ var lastLoopingChecked = StorageValue < Date ? > ( key: " lastLoopingChecked " , defaultValue: nil )
164+
163165 static let shared = Storage ( )
164166 private init ( ) { }
165167}
You can’t perform that action at this time.
0 commit comments