question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for multiple batteries

See original GitHub issue

I’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:open
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nwg-piotrcommented, Aug 1, 2022

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.

0reactions
marekjwcommented, Aug 1, 2022
alia3% upower -e | grep devices/battery
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/battery_BAT1

I think detecting only the first battery is expected behaviour in psutils: https://github.com/giampaolo/psutil/blob/57ed46de8a988e7ab26279c2a967fb15b05397a3/psutil/_pslinux.py#L1468

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connecting Batteries & Chargers in Series & Parallel
Figure 2 shows two 12-volt batteries connected in series. The important things to note about a series connection are: 1) The battery voltages...
Read more >
How to Wire Multiple Batteries to an RV with Josh the RV Nerd
Download the Wiring Helper Guide here: https://www.haylettautoandrv.com/wp-content/uploads/2021/04/Wiring- Multiple - Batteries -scaled.
Read more >
Optimal Charging for Multiple Batteries in a Bank
When connecting multiple batteries in parallel to create a larger battery bank, it turns out that “not all batteries are ... ies are...
Read more >
how-configure-battery-bank - Web - Windy Nation
While from an electrical perspective, this is correct, when more than two batteries are in parallel, adding the third and fourth batteries in...
Read more >
Multi Battery Connections - VDC Electronics - BatteryMINDers
When you connect multiple batteries in series, connect the + of the first battery to the - of the second one. To add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found