utkarsh2102 / batalert

Battery notifications/alerts for your favorite WM! 💯
MIT License
8 stars 2 forks source link

batalert: Fails to start because BAT0 is assumed #4

Open utkarsh2102 opened 3 years ago

utkarsh2102 commented 3 years ago

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: https://github.com/utkarsh2102/batalert/blob/703e816bcecfe56962f5cc91c041164cb9425c68/lib/batalert.rb#L14-L18

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

utkarsh2102 commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

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

utkarsh2102 commented 2 years ago

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 commented 1 year ago

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