Skip to content

Commit 64e3382

Browse files
authored
Improve charging detection (#332)
1 parent 78ddf14 commit 64e3382

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

auto_cpufreq/core.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
)
4040
CPUS = os.cpu_count()
4141

42+
# ignore these devices under /sys/class/power_supply/
43+
POWER_SUPPLY_IGNORELIST = ["hidpp_battery"]
44+
4245
# Note:
4346
# "load1m" & "cpuload" can't be global vars and to in order to show correct data must be
4447
# decraled where their execution takes place
@@ -194,6 +197,8 @@ def charging():
194197
"""
195198
power_supply_path = "/sys/class/power_supply/"
196199
power_supplies = os.listdir(Path(power_supply_path))
200+
# sort it so AC is 'always' first
201+
power_supplies = sorted(power_supplies)
197202

198203
# check if we found power supplies. on a desktop these are not found
199204
# and we assume we are on a powercable.
@@ -203,10 +208,12 @@ def charging():
203208
# we found some power supplies, lets check their state
204209
else:
205210
for supply in power_supplies:
206-
# skip battery of hid devices
207-
# see issue #321
208-
if "hid" in supply.lower():
211+
# Check if supply is in ignore list
212+
ignore_supply = any(item in supply for item in POWER_SUPPLY_IGNORELIST)
213+
# If found in ignore list, skip it.
214+
if ignore_supply:
209215
continue
216+
210217
try:
211218
with open(Path(power_supply_path + supply + "/type")) as f:
212219
supply_type = f.read()[:-1]

0 commit comments

Comments
 (0)