Add support for multiple batteries
See original GitHub issueI’m using a laptop with two batteries. However, only the capacity of the first one is displayed in panel, making it impossible to judge for how long the battery will last.
It would be best if the get_battery
function (tools.py:483
) automatically checked for multiple batteries, and adjusted the total percentage accordingly.
Unfortunately, it seems that psutils.sensors_battery()
doesn’t support multiple batteries. In that case, a simple script to calculate the current capacity could be used.
In the following example, you can see that my total battery percent is significantly lower than indicated by psutil
alia3% python
Python 3.10.5 (main, Jun 6 2022, 18:49:26) [GCC 12.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.sensors_battery()
sbattery(percent=69.56521739130434, secsleft=5685, power_plugged=False)
>>>
alia3% cat /sys/class/power_supply/BAT0/capacity
69
alia3% cat /sys/class/power_supply/BAT1/capacity
5
I’ve written a simple script to get total current percentage, something similar could be used as a temporary workaround, maybe?
#! /bin/bash
FULL_SUM=0
NOW_SUM=0
for bat in /sys/class/power_supply/BAT*; do
FULL_SUM=$(( FULL_SUM + $(cat $bat/energy_full) ))
NOW_SUM=$(( NOW_SUM + $(cat $bat/energy_now) ))
done
echo $(( 100 * NOW_SUM / FULL_SUM ))
(Note that batteries might have different capacities, hence the need to calculate the sum manually)
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Yes, but nwg-panel already uses
upower
as an alternative method. We would only need to add some settings to force use of it, and to make use of multiple results.I think detecting only the first battery is expected behaviour in
psutils
: https://github.com/giampaolo/psutil/blob/57ed46de8a988e7ab26279c2a967fb15b05397a3/psutil/_pslinux.py#L1468