upower shows incorrect battery percentage due to energy-full being overcalculated
For some reason, energy
will sometimes significantly overshoot energy-full-design
. I'm not entirely sure what the cause is, but the systemd journal log will report entries like:
energy 450.0 bigger than full 80.0
This is just a blip though, and energy
is soon reverted back to a normal value (<energy-full-design
). However, since energy-full
is now set to that larger value (https://gitlab.freedesktop.org/upower/upower/-/blob/ce2478716517df002175d0c4f57c057a0977ccb3/src/linux/up-device-supply.c#L637), the battery percentage is then calculated as <10%, even if the actual value is much higher. Note that capacity
(which reads the battery percentage from sysfs) is properly calculated.
Since this can cause numerous system problems (preemptive hibernation, battery alerts, etc.), I implemented a stop-gap fix on my computer that recalculates coldplug values on every refresh (https://gitlab.freedesktop.org/upower/upower/-/blob/ce2478716517df002175d0c4f57c057a0977ccb3/src/linux/up-device-supply.c#L535
-> if (1)
).
I believe this issue is related: #136 (closed), though the make/model of my computer is different (macbook air).
I'm not sure what causes the energy
blip, it's probably some kind of firmware bug. I'm not sure what a proper fix should be either, as I don't believe my stop-gap fix is necessarily a good idea since it eliminates the cache entirely. Perhaps a threshold for energy > energy_full
? e.g. if (energy / energy_full > 2.) { ... }
In my observance, the blip is usually ~5-10x the size of energy-full-design
.