mirror of
https://github.com/henrygd/beszel.git
synced 2025-12-17 10:46:16 +01:00
add battery charge monitoring
This commit is contained in:
18
beszel/internal/agent/battery.go
Normal file
18
beszel/internal/agent/battery.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package agent
|
||||
|
||||
import "github.com/distatus/battery"
|
||||
|
||||
// getBatteryStats returns the current battery percent and charge state
|
||||
func getBatteryStats() (batteryPercent uint8, batteryState uint8, err error) {
|
||||
bat, err := battery.Get(0)
|
||||
if err != nil {
|
||||
return batteryPercent, batteryState, err
|
||||
}
|
||||
full := bat.Design
|
||||
if full == 0 {
|
||||
full = bat.Full
|
||||
}
|
||||
batteryPercent = uint8(bat.Current / full * 100)
|
||||
batteryState = uint8(bat.State.Raw)
|
||||
return batteryPercent, batteryState, nil
|
||||
}
|
||||
Reference in New Issue
Block a user