Skip to content

Questions about BAT0 or BAT1 in battery.sh #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ycpss91255 opened this issue Dec 12, 2024 · 3 comments · Fixed by #469 or #480
Closed

Questions about BAT0 or BAT1 in battery.sh #455

ycpss91255 opened this issue Dec 12, 2024 · 3 comments · Fixed by #469 or #480

Comments

@ycpss91255
Copy link

it doesn't exist on my lattop (LG, Ubuntu 24.04 and Ubuntu 20.04). My laptop only has CMB0. I replaced BAT0 in .sh with CMB0 to make it work properly.

@erikw
Copy link
Owner

erikw commented Feb 8, 2025

Oh look at that. It looks like this code should be a bit smarter and not just assume two names (BAT0 or BAT1):

BATPATH=/sys/class/power_supply/BAT0
if [ ! -d $BATPATH ]; then
BATPATH=/sys/class/power_supply/BAT1

We could look for these most common names (BAT0 or BAT1), or else pick the one other battery name (if any) if those two first one does not exist.

Would you be willing to make a PR? :)

@xx4h
Copy link
Collaborator

xx4h commented May 15, 2025

This has been closed accidentally. The issue is about CMB?-naming instead of BAT?, while the referenced and merged PR is about having multiple BAT? (instead of only supporting hard coded BAT0 and BAT1)

I see two reasonable approaches

  1. Clean implementation
    We get all power supply entries with type=Battery.
while read bat; do
        local full="$bat/charge_full"
        local now="$bat/charge_now"
        ...
done <<<$(grep -l "Battery" /sys/class/power_supply/*/type | sed -e 's,/type$,,')
  1. Quick Fix
    We add CMB* to the loop
for bat in /sys/class/power_supply/{BAT,CMB}*; do
    ...

Of course i'll recommend 1., will make a PR as soon as we're aligned.

@xx4h xx4h reopened this May 15, 2025
@erikw
Copy link
Owner

erikw commented May 15, 2025

Oh yes you are correct, I incorrectly linked this issue to the mentioned PR. Sorry! Thanks for noticing:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants