fix: send battery stats even if some batteries are missing stats (#1287)

Implement battery error reporting mechanism

Added error reporting for battery information retrieval.

Handles cases like bluetooth devices where `battery` finds it but it has incomplete information about that battery, which would have otherwise caused a null pointer error.

Related: #1254
This commit is contained in:
Nathan Heaps
2025-10-25 13:23:29 -04:00
committed by GitHub
parent b9139a1f9b
commit d608cf0955
3 changed files with 49 additions and 21 deletions

View File

@@ -78,8 +78,9 @@ func (a *Agent) getSystemStats(cacheTimeMs uint16) system.Stats {
var systemStats system.Stats
// battery
if battery.HasReadableBattery() {
systemStats.Battery[0], systemStats.Battery[1], _ = battery.GetBatteryStats()
if batteryPercent, batteryState, err := battery.GetBatteryStats(); err == nil {
systemStats.Battery[0] = batteryPercent
systemStats.Battery[1] = batteryState
}
// cpu percent