rickysarraf / laptop-mode-tools

Power Savings tool for Linux
https://www.researchut.com/tags/laptop-mode-tools/
GNU General Public License v2.0
550 stars 47 forks source link

/sys/class/power_supply/* is too broad a search, suggest scanning just /sys/class/power_supply/BAT* #207

Open BillyCroan opened 7 months ago

BillyCroan commented 7 months ago

If your laptop has a peripheral device with a battery, laptop-mode-tools reacts as if that devices battery is the laptop's and reacts poorly when that peripheral doesn't support a design_capacity. I was getting tonnes of this in my syslog:

2024-01-14T20:49:11.499724-06:00 x360 laptop_mode[1483528]: WARNING: Battery does not report a capacity. Minimum battery
2024-01-14T20:49:11.502666-06:00 x360 laptop_mode[1483528]: charge checking does not work without a design capacity.
2024-01-14T20:49:11.502742-06:00 x360 laptop_mode[1483528]: WARNING: Battery does not report a design capacity. Auto hibernation
2024-01-14T20:49:11.502781-06:00 x360 laptop_mode[1483528]: does not work without a design capacity.
2024-01-14T20:49:11.502812-06:00 x360 laptop_mode[1483528]: You seem to have a broken battery
2024-01-14T20:49:11.502838-06:00 x360 laptop_mode[1483528]: Cannot determine design_capacity_warning
2024-01-14T20:49:11.502876-06:00 x360 laptop_mode[1483528]: Disabling hibernation
2024-01-14T20:49:11.502942-06:00 x360 laptop_mode[1483528]: Failed to determine battery charge. Battery charge units are not in
2024-01-14T20:49:11.502976-06:00 x360 laptop_mode[1483528]: mWh, uWh, mAh or uAh.
2024-01-14T20:49:11.503002-06:00 x360 laptop_mode[1483528]: Laptop mode
2024-01-14T20:49:11.503221-06:00 x360 laptop_mode[1483528]: enabled, active [unchanged]
2024-01-14T20:49:11.503282-06:00 x360 systemd[1]: Reloaded laptop-mode.service - Laptop Mode Tools.

This is because line750: for BATT in /sys/class/power_supply/* ; do

That captures all batteries, when I think we're really looking for BAT0. and maybe some laptops have a BAT1 or 2

What you don't want is to match on hid-0018:04F3:272D.0002-battery or the like

So I edited like 750 to: for BATT in /sys/class/power_supply/BAT* ; do

And now my syslog is much happier. no more angry messages.

If you really don't want to narrow down to BAT then perhaps check on like 751 that BATT does not begin with "hid-"

I hope this bug report helps other users who were having the broken battery warnings, and helps improve the laptop-mode-tools project.