Skip to content
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

batalert: Fails to start because BAT0 is assumed #4

Open
utkarsh2102 opened this issue Jun 28, 2021 · 5 comments
Open

batalert: Fails to start because BAT0 is assumed #4

utkarsh2102 opened this issue Jun 28, 2021 · 5 comments

Comments

@utkarsh2102
Copy link
Owner

From debbug #988091:

I get this error when running batalert:

$ batalert
Traceback (most recent call last):
        5: from /usr/bin/batalert:23:in `<main>'
       4: from /usr/bin/batalert:23:in `load'
       3: from /usr/share/rubygems-integration/all/gems/batalert-0.4.0/exe/batalert:5:in `<top (required)>'
       2: from /usr/share/rubygems-integration/all/gems/batalert-0.4.0/lib/batalert.rb:14:in `main'
       1: from /usr/share/rubygems-integration/all/gems/batalert-0.4.0/lib/batalert.rb:14:in `open'/usr/share/rubygems-
integration/all/gems/batalert-0.4.0/lib/batalert.rb:14:in `initialize': No such file or directory @ rb_sysopen -
/sys/class/power_supply/BAT0/capacity (Errno::ENOENT)

This appears to be caused by batalert making an incorrect assumption
about the battery name:

$ ls /sys/class/power_supply/
ACAD  BAT1

...which is true! See here:

batalert/lib/batalert.rb

Lines 14 to 18 in 703e816

capacity = File.open('/sys/class/power_supply/BAT0/capacity', &:readline)
capacity = capacity.to_i
status = File.open('/sys/class/power_supply/BAT0/status', &:readline)
status = status.chomp

Probably worth figuring out which BAT* is there separately? Maybe I'll go ahead and re-write this in a much better way.

@utkarsh2102
Copy link
Owner Author

Hm, looks like this could work:

# utkarsh @ utkarsh2102 in ~ [1:54:20] 
$ irb
irb(main):001:0> require "find"
=> true
irb(main):002:0> Find.find('/sys/class/power_supply/').grep(/BAT/)
=> ["/sys/class/power_supply/BAT0"]

@henrythemouse
Copy link

Likely you never had this in mind. I'd like to use this on an linux phone. There isn't any BAT* under power_supply. On the pine phone pro there are three directories there:

rk818-battery (with 4 more dirs under that and other subdirs under those with more files under each)
rk818-usb (similar dir sub-structure as above)
tcpm-source-psy-4-002 (similar dir sub-structure as above)

The phone is running Mobian, which is debian bookworm with a custom gnome shell. The phone does display notifications and I've written scripts using notify-send that work fine.

@rajudev
Copy link

rajudev commented Oct 14, 2022

Faced the same issue on my machine after installing from the latest commit.

@utkarsh2102
Copy link
Owner Author

Okay, I am going to use upower to fix this on the laptop/machine side. I still need to look at the pine phone thingy separately.

@Animesh-Ghosh
Copy link

@utkarsh2102 might I suggest k-nowicki/rupower as the Ruby interface for upower?

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

No branches or pull requests

4 participants