mirror of
https://github.com/henrygd/beszel.git
synced 2026-03-26 07:26:16 +01:00
Compare commits
2 Commits
battery
...
fb3c70a1bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb3c70a1bc | ||
|
|
cba4d60895 |
@@ -4,15 +4,21 @@ 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)
|
||||
batteries, err := battery.GetAll()
|
||||
if err != nil {
|
||||
return batteryPercent, batteryState, err
|
||||
}
|
||||
full := bat.Design
|
||||
if full == 0 {
|
||||
full = bat.Full
|
||||
totalCapacity := float64(0)
|
||||
totalCharge := float64(0)
|
||||
for _, bat := range batteries {
|
||||
if bat.Design != 0 {
|
||||
totalCapacity += bat.Design
|
||||
} else {
|
||||
totalCapacity += bat.Full
|
||||
}
|
||||
totalCharge += bat.Current
|
||||
}
|
||||
batteryPercent = uint8(bat.Current / full * 100)
|
||||
batteryState = uint8(bat.State.Raw)
|
||||
batteryPercent = uint8(totalCharge / totalCapacity * 100)
|
||||
batteryState = uint8(batteries[0].State.Raw)
|
||||
return batteryPercent, batteryState, nil
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ const ChartLegendContent = React.forwardRef<
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex items-center justify-center gap-4 gap-y-1 flex-wrap",
|
||||
"flex items-center justify-center gap-4 gap-y-1 flex-wrap ps-4",
|
||||
verticalAlign === "top" ? "pb-3" : "pt-3",
|
||||
className
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user