Browse Source

add uploader isCharging attribute to NS device status upload

Paul Plant 1 year ago
parent
commit
0b15a492ae

+ 1 - 0
FreeAPS/Sources/Models/NightscoutStatus.swift

@@ -24,6 +24,7 @@ struct NSPumpStatus: JSON {
 struct Uploader: JSON {
     let batteryVoltage: Decimal?
     let battery: Int
+    let isCharging: Bool?
 }
 
 struct NightscoutTimevalue: JSON {

+ 7 - 2
FreeAPS/Sources/Services/Network/NightscoutManager.swift

@@ -451,8 +451,13 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
             status: pumpStatus
         )
 
-        let device = await UIDevice.current
-        let uploader = await Uploader(batteryVoltage: nil, battery: Int(device.batteryLevel * 100))
+        let batteryLevel = await UIDevice.current.batteryLevel
+        let batteryState = await UIDevice.current.batteryState
+        let uploader = Uploader(
+            batteryVoltage: nil,
+            battery: Int(batteryLevel * 100),
+            isCharging: batteryState == .charging || batteryState == .full
+        )
         let status = NightscoutStatus(
             device: NightscoutTreatment.local,
             openaps: openapsStatus,