distatus / battery

cross-platform, normalized battery information library
MIT License
249 stars 36 forks source link

No such device error #33

Open coderGtm opened 9 months ago

coderGtm commented 9 months ago

When I run the battery.GetAll() function, it gives me the following error:

panic: [{ChargeRate:read /sys/class/power_supply/BAT1/power_now: no such device}]

While I was tinkering, I found out that the ls command did show a file named power_now but opening it with cat gives the same error as above. On the other hand, I found out that there is another file called capacity which gives the battery level.

I am on Arch Linux and using go 1.21.6.

KenjiTakahashi commented 8 months ago

Interesting, usually I'd say that it is the controller misbehaving in some way, but who knows?

Do you have any way of testing on another OS (i.e. not Linux)? Also, the output of ls -l /sys/class/power_supply/BAT1/ (mind the slash at the end!) can be useful.

coderGtm commented 8 months ago

I have switched from Arch to Ubuntu in the meantime so not sure if it still is an issue but will try to run it on my University's Windows PC. Although I don't understand why I should run it on Windows.

kivattt commented 4 months ago

I get the same error on my Linux Mint 21.3 x86_64 laptop, though I can safely ignore it atleast if I'm just looking at battery.State.String()

KenjiTakahashi commented 4 months ago

@kivattt It would be great if you could do what I mentioned in the previous comment. Maybe then I'll be able to get an idea on how to fix this, as I have never encountered it myself.

kivattt commented 3 months ago
$ /bin/ls -l /sys/class/power_supply/BAT1/
/bin/ls: cannot access '/sys/class/power_supply/BAT1/': No such file or directory
$ /bin/ls -l /sys/class/power_supply/
total 0
lrwxrwxrwx 1 root root 0 Jul 19 19:07 AC -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/AC
lrwxrwxrwx 1 root root 0 Jul 19 19:07 BAT0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0
KenjiTakahashi commented 3 months ago

Thanks! OK, so you don't have a BAT1 device. Therefore in your case it would be ls -l /sys/class/power_supply/BAT0/ instead.

kivattt commented 3 months ago

My bad,

$ /bin/ls -l /sys/class/power_supply/BAT0/
total 0
-rw-r--r-- 1 root root 4096 Jul 26 00:09 alarm
-r--r--r-- 1 root root 4096 Jul 19 19:07 capacity
-r--r--r-- 1 root root 4096 Jul 26 00:09 capacity_level
-r--r--r-- 1 root root 4096 Jul 19 19:07 charge_full
-r--r--r-- 1 root root 4096 Jul 19 19:07 charge_full_design
-r--r--r-- 1 root root 4096 Jul 19 19:07 charge_now
-r--r--r-- 1 root root 4096 Jul 19 19:07 current_now
-r--r--r-- 1 root root 4096 Jul 19 19:07 cycle_count
lrwxrwxrwx 1 root root    0 Jul 19 19:07 device -> ../../../PNP0C0A:00
drwxr-xr-x 3 root root    0 Jul 19 19:07 hwmon2
-r--r--r-- 1 root root 4096 Jul 19 19:07 manufacturer
-r--r--r-- 1 root root 4096 Jul 19 19:07 model_name
drwxr-xr-x 2 root root    0 Jul 26 00:09 power
-r--r--r-- 1 root root 4096 Jul 19 19:07 present
-r--r--r-- 1 root root 4096 Jul 19 19:07 serial_number
-r--r--r-- 1 root root 4096 Jul 19 19:07 status
lrwxrwxrwx 1 root root    0 Jul 19 19:07 subsystem -> ../../../../../../class/power_supply
-r--r--r-- 1 root root 4096 Jul 19 19:07 technology
-r--r--r-- 1 root root 4096 Jul 19 19:07 type
-rw-r--r-- 1 root root 4096 Jul 19 19:07 uevent
-r--r--r-- 1 root root 4096 Jul 19 19:07 voltage_min_design
-r--r--r-- 1 root root 4096 Jul 19 19:07 voltage_now