giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.19k stars 1.38k forks source link

Only first battery reported with psutil.sensors_battery() #1460

Open VorpalBlade opened 5 years ago

VorpalBlade commented 5 years ago

Linux

Bug description

On Linux the first battery is reported. Some laptops (such as Lenovo Thinkpad T480) has two batteries, one built in, and one removable. The information about the removable battery is not reported Example:

In [7]: psutil.sensors_battery()                                                                                                                                                                                                     
Out[7]: sbattery(percent=92.84843559528647, secsleft=<BatteryTime.POWER_TIME_UNLIMITED: -2>, power_plugged=True)

But two batteries (and AC) are available in the sys filesystem:

$ ls /sys/class/power_supply/
AC  BAT0  BAT1
giampaolo commented 5 years ago

Yeah, that's by design (at the moment). We may want to introduce a all=False parameter or something. When True it should return a list of namedtuples.

amanusk commented 5 years ago

@giampaolo I can try and take a look at this

giampaolo commented 5 years ago

Go for it Alex.

mohkale commented 3 years ago

I'm using psutil to create components for my tmux status-line and it seems to be picking up the baterry level for my bluetooth keyboard by default :joy:, any idea if #1466 might be merged soon?