Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion LoopFollow/Alarm/AlarmCondition/NotLoopingCondition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct NotLoopingCondition: AlarmCondition {
static let type: AlarmType = .notLooping
init() {}

func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
func evaluate(alarm: Alarm, data: AlarmData, now: Date) -> Bool {
// ────────────────────────────────
// 0. sanity checks
// ────────────────────────────────
Expand All @@ -19,6 +19,17 @@ struct NotLoopingCondition: AlarmCondition {
guard let lastLoopTime = data.lastLoopTime,
lastLoopTime > 0 else { return false }

guard let lastChecked = Storage.shared.lastLoopingChecked.value else {
// Never checked, so don't alarm.
return false
}

let checkedAgeSeconds = now.timeIntervalSince(lastChecked)
if checkedAgeSeconds > 360 { // 6 minutes
// The check itself is stale, so the data is unreliable. Don't alarm.
return false
}

// ────────────────────────────────
// 1. elapsed-time test
// ────────────────────────────────
Expand Down
2 changes: 2 additions & 0 deletions LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import UIKit

extension MainViewController {
func webLoadNSDeviceStatus() {
Storage.shared.lastLoopingChecked.value = Date()

let parameters = ["count": "1"]
NightscoutUtils.executeDynamicRequest(eventType: .deviceStatus, parameters: parameters) { result in
switch result {
Expand Down
2 changes: 2 additions & 0 deletions LoopFollow/Storage/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class Storage {
var persistentNotification = StorageValue<Bool>(key: "persistentNotification", defaultValue: false)
var persistentNotificationLastBGTime = StorageValue<Date>(key: "persistentNotificationLastBGTime", defaultValue: .distantPast)

var lastLoopingChecked = StorageValue<Date?>(key: "lastLoopingChecked", defaultValue: nil)

static let shared = Storage()
private init() {}
}