fastfetch-cli / fastfetch

An actively maintained, feature-rich and performance oriented, neofetch like system information tool.
MIT License
9.74k stars 390 forks source link

Battery info on AC #118

Closed DarNCelsius closed 2 years ago

DarNCelsius commented 2 years ago

I get battery info when on AC. I don't know if this is meant to output device or laptop battery info, but if it's the former, some info on the device would probably be good. If it's the latter, I'd consider it a bug. It's only picking up the mouse not the keyboard.

Output of fastfetch --version:

fastfetch r511.d4f753a

Output of fastfetch --load-config devinfo-verbose:

Battery: Manufactor: Logitech; Model: G703 LIGHTSPEED Wireless Gaming Mouse w/ HERO; Technology: ; Capacaty: 96; Status: Discharging

Output of fastfetch --list-features:

libpci
vulkan
x11
xrandr
wayland
gio
dconf
xfconf

Happens both in zsh and bash

LinusDierheimer commented 2 years ago

That is definitely a bug. The module is supposed to show the capacity of the battery, so mostly useful for Laptops. The model is only exposed to the format string, so not shown by default. On desktop stations, it usually doesn't show up, because the kernel doesn't expose anything as battery.

Scanning for batteries works by iterating /sys/class/power_supply/ and finding subfolders containing a capacity file. It seems like your mouse exposes its battery status to the kernel too, so it creates an interface for it, which we obviously doesn't want to show. So there must be a way to defer between the types of the battery devices. Does the subfolder for your mouse contain a type file, and if yes, what is its content?

LinusDierheimer commented 2 years ago

At this point i'm thinking of rewriting the battery code to parse /sys/class/power_supply/*/uevent, instead of reading a lot of small files. Does the content of this file match the contents of the other files in your case?

DarNCelsius commented 2 years ago

The mouse uses a "G PowerPlay Wireless Charging System", which could be a special case I guess. /sys/class/power_supply/ contains two folders; one for the keyboard and one for the mouse.

Mouse/hidpp_battery_1:

cat /sys/class/power_supply/hidpp_battery_1/type

Battery
cat /sys/class/power_supply/hidpp_battery_1/uevent

POWER_SUPPLY_NAME=hidpp_battery_1
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=G703 LIGHTSPEED Wireless Gaming Mouse w/ HERO
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=4086-d2-aa-ef-bb
POWER_SUPPLY_CAPACITY=87
POWER_SUPPLY_VOLTAGE_NOW=4043000

Keyboard/hidpp_battery_0:

cat /sys/class/power_supply/hidpp_battery_0/type

Battery
cat /sys/class/power_supply/hidpp_battery_0/uevent

POWER_SUPPLY_NAME=hidpp_battery_0
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=MX Keys Wireless Keyboard
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=408a-6e-19-09-47
POWER_SUPPLY_CAPACITY_LEVEL=Full

Folders:

╭─    /sys/class/power_supply/hidpp_battery_0                                                                                                                                                                                           ✔  09:51:17 
╰─ ls
total 0
lrwxrwxrwx 1 root root    0 24.12.2021 09:35 device -> ../../../0003:046D:408A.000F/
drwxr-xr-x 3 root root    0 24.12.2021 09:35 hwmon8/
drwxr-xr-x 2 root root    0 24.12.2021 09:45 power/
lrwxrwxrwx 1 root root    0 24.12.2021 09:45 powers -> ../../../0003:046D:408A.000F/
lrwxrwxrwx 1 root root    0 24.12.2021 09:35 subsystem -> ../../../../../../../../../../../../../../class/power_supply/
drwxr-xr-x 2 root root    0 24.12.2021 09:35 wakeup54/
-r--r--r-- 1 root root 4,0K 24.12.2021 09:35 capacity_level
-r--r--r-- 1 root root 4,0K 24.12.2021 09:45 manufacturer
-r--r--r-- 1 root root 4,0K 24.12.2021 09:35 model_name
-r--r--r-- 1 root root 4,0K 24.12.2021 09:45 online
-r--r--r-- 1 root root 4,0K 24.12.2021 09:35 scope
-r--r--r-- 1 root root 4,0K 24.12.2021 09:35 serial_number
-r--r--r-- 1 root root 4,0K 24.12.2021 09:35 status
-r--r--r-- 1 root root 4,0K 24.12.2021 09:35 type
-rw-r--r-- 1 root root 4,0K 24.12.2021 09:35 uevent
╭─    /sys/class/power_supply/hidpp_battery_1                                                                                                                                                                                           ✔  09:51:28 
╰─ ls
total 0
lrwxrwxrwx 1 root root    0 24.12.2021 09:36 device -> ../../../0003:046D:4086.0010/
drwxr-xr-x 3 root root    0 24.12.2021 09:36 hwmon9/
drwxr-xr-x 2 root root    0 24.12.2021 09:38 power/
lrwxrwxrwx 1 root root    0 24.12.2021 09:38 powers -> ../../../0003:046D:4086.0010/
lrwxrwxrwx 1 root root    0 24.12.2021 09:36 subsystem -> ../../../../../../../../../../../../../../class/power_supply/
drwxr-xr-x 2 root root    0 24.12.2021 09:36 wakeup55/
-r--r--r-- 1 root root 4,0K 24.12.2021 09:36 capacity
-r--r--r-- 1 root root 4,0K 24.12.2021 09:37 manufacturer
-r--r--r-- 1 root root 4,0K 24.12.2021 09:36 model_name
-r--r--r-- 1 root root 4,0K 24.12.2021 09:38 online
-r--r--r-- 1 root root 4,0K 24.12.2021 09:36 scope
-r--r--r-- 1 root root 4,0K 24.12.2021 09:36 serial_number
-r--r--r-- 1 root root 4,0K 24.12.2021 09:36 status
-r--r--r-- 1 root root 4,0K 24.12.2021 09:36 type
-rw-r--r-- 1 root root 4,0K 24.12.2021 09:36 uevent
-r--r--r-- 1 root root 4,0K 24.12.2021 09:38 voltage_now

The mouse has a 'capacity' file, the keyboard a 'capacity_level' file.

LinusDierheimer commented 2 years ago

That is very similar to the battery on my laptop:

cat /sys/class/power_supply/BAT0/uevent

POWER_SUPPLY_NAME=BAT0
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_STATUS=Charging
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_TECHNOLOGY=Li-poly
POWER_SUPPLY_CYCLE_COUNT=0
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11400000
POWER_SUPPLY_VOLTAGE_NOW=12729000
POWER_SUPPLY_CURRENT_NOW=413000
POWER_SUPPLY_CHARGE_FULL_DESIGN=4474000
POWER_SUPPLY_CHARGE_FULL=3750000
POWER_SUPPLY_CHARGE_NOW=3692000
POWER_SUPPLY_CAPACITY=98
POWER_SUPPLY_CAPACITY_LEVEL=Normal
POWER_SUPPLY_MODEL_NAME=DELL PN1VN08
POWER_SUPPLY_MANUFACTURER=SMP-ATL4.49
POWER_SUPPLY_SERIAL_NUMBER= 2958

I miss POWER_SUPPLY_SCOPE. I think this is the key. So to implement i right i will have to check:

I am bit stressed with studies right now, but it is on my todo.

Edit: neofetch does the following:

for bat in "/sys/class/power_supply/"{BAT,axp288_fuel_gauge,CMB}*; do

Maybe this is better? I feel like this likely to miss something out. Neofetch has some of those restrictive tests, i don't want to bring them into fastfetch.

LinusDierheimer commented 2 years ago

Should be working.

DarNCelsius commented 2 years ago

Confirmed. Happy new year Linus. :grin: