diff --git a/LoopFollow/Controllers/Nightscout/DeviceStatus.swift b/LoopFollow/Controllers/Nightscout/DeviceStatus.swift index 7fb1750dc..bc8443cf8 100644 --- a/LoopFollow/Controllers/Nightscout/DeviceStatus.swift +++ b/LoopFollow/Controllers/Nightscout/DeviceStatus.swift @@ -67,7 +67,7 @@ extension MainViewController { func updateDeviceStatusDisplay(jsonDeviceStatus: [[String: AnyObject]]) { let previousIOBText = Observable.shared.iobText.value let previousDeviceWasLoop = Storage.shared.device.value == "Loop" - infoManager.clearInfoData(types: [.iob, .cob, .battery, .pump, .pumpBattery, .target, .isf, .carbRatio, .updated, .recBolus, .tdd, .smoothedBG]) + infoManager.clearInfoData(types: [.iob, .cob, .battery, .pump, .pumpBattery, .target, .isf, .carbRatio, .updated, .recBolus, .tdd, .smoothedBG, .watchBattery]) // For Loop, clear the current override here - For Trio, it is handled using treatments if Storage.shared.device.value == "Loop" { @@ -184,6 +184,15 @@ extension MainViewController { deviceBatteryData.removeFirst() } } + + // Trio adds the Apple Watch's battery while the watch reported it within the last hour + if let watch = lastDeviceStatus?["watchBattery"] as? [String: AnyObject], + let level = (watch["battery"] as? NSNumber)?.doubleValue + { + let charging = watch["isCharging"] as? Bool == true + let text = (charging ? "⚡️ " : "") + String(format: "%.0f", level) + "%" + infoManager.updateInfoData(type: .watchBattery, value: text, numericValue: level) + } } // Loop - handle new data diff --git a/LoopFollow/InfoTable/InfoType.swift b/LoopFollow/InfoTable/InfoType.swift index ca127c027..952f4df9d 100644 --- a/LoopFollow/InfoTable/InfoType.swift +++ b/LoopFollow/InfoTable/InfoType.swift @@ -4,7 +4,7 @@ import Foundation enum InfoType: Int, CaseIterable, Codable { - case iob, cob, basal, override, battery, pump, pumpBattery, sage, cage, recBolus, minMax, carbsToday, autosens, profile, target, isf, carbRatio, updated, tdd, iage, dbSize, smoothedBG + case iob, cob, basal, override, battery, pump, pumpBattery, sage, cage, recBolus, minMax, carbsToday, autosens, profile, target, isf, carbRatio, updated, tdd, iage, dbSize, smoothedBG, watchBattery var name: String { switch self { @@ -30,6 +30,7 @@ enum InfoType: Int, CaseIterable, Codable { case .iage: return "IAGE" case .dbSize: return "DB Size" case .smoothedBG: return "Smoothed BG" + case .watchBattery: return "Watch Battery" } } @@ -57,7 +58,7 @@ enum InfoType: Int, CaseIterable, Codable { return InfoColorConfig(direction: .above, unit: "U", range: 0 ... 20, step: 0.5, defaultWarning: 3, defaultUrgent: 5) case .cob: return InfoColorConfig(direction: .above, unit: "g", range: 0 ... 200, step: 1, defaultWarning: 30, defaultUrgent: 60) - case .battery, .pumpBattery: + case .battery, .pumpBattery, .watchBattery: return InfoColorConfig(direction: .below, unit: "%", range: 0 ... 100, step: 5, defaultWarning: 30, defaultUrgent: 15) case .pump: return InfoColorConfig(direction: .below, unit: "U", range: 0 ... 50, step: 1, defaultWarning: 20, defaultUrgent: 10)