Skip to content

Commit

Permalink
Only fetch 5 devicestatus if last attempt resulted in suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorkert committed Jan 26, 2025
1 parent 4aa0029 commit a819fe1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions LoopFollow/Controllers/Nightscout/DeviceStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import Charts
extension MainViewController {
// NS Device Status Web Call
func webLoadNSDeviceStatus() {
let count = ObservableUserDefaults.shared.device.value == "Trio" ? "5" : "1"
LogManager.shared.log(category: .deviceStatus, message: "Fetching \(count) device status records", isDebug: true)
let count = ObservableUserDefaults.shared.device.value == "Trio" && Observable.shared.isLastDeviceStatusSuggested.value ? "5" : "1"
if count != "1" {
LogManager.shared.log(category: .deviceStatus, message: "Fetching \(count) device status records")
}

let parameters: [String: String] = ["count": count]
NightscoutUtils.executeDynamicRequest(eventType: .deviceStatus, parameters: parameters) { result in
Expand Down
2 changes: 2 additions & 0 deletions LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extension MainViewController {
wasEnacted = false
}

Observable.shared.isLastDeviceStatusSuggested.value = !wasEnacted

if wasEnacted {
UserDefaultsRepository.alertLastLoopTime.value = lastLoopTime
LogManager.shared.log(category: .deviceStatus, message: "New LastLoopTime: \(lastLoopTime)", isDebug: true)
Expand Down
1 change: 1 addition & 0 deletions LoopFollow/Storage/Observable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Observable {

var tempTarget = ObservableValue<HKQuantity?>(default: nil)
var override = ObservableValue<String?>(default: nil)
var isLastDeviceStatusSuggested = ObservableValue<Bool>(default: false)

private init() {}
}

0 comments on commit a819fe1

Please sign in to comment.