From 64e33827b82d895e30f10f887479b5ee834b703e Mon Sep 17 00:00:00 2001 From: bobslept <38557801+bobslept@users.noreply.github.com> Date: Fri, 24 Dec 2021 20:21:40 +0100 Subject: [PATCH] Improve charging detection (#332) --- auto_cpufreq/core.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 7dd262f..8c865a9 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -39,6 +39,9 @@ ALL_GOVERNORS = ( ) CPUS = os.cpu_count() +# ignore these devices under /sys/class/power_supply/ +POWER_SUPPLY_IGNORELIST = ["hidpp_battery"] + # Note: # "load1m" & "cpuload" can't be global vars and to in order to show correct data must be # decraled where their execution takes place @@ -194,6 +197,8 @@ def charging(): """ power_supply_path = "/sys/class/power_supply/" power_supplies = os.listdir(Path(power_supply_path)) + # sort it so AC is 'always' first + power_supplies = sorted(power_supplies) # check if we found power supplies. on a desktop these are not found # and we assume we are on a powercable. @@ -203,10 +208,12 @@ def charging(): # we found some power supplies, lets check their state else: for supply in power_supplies: - # skip battery of hid devices - # see issue #321 - if "hid" in supply.lower(): + # Check if supply is in ignore list + ignore_supply = any(item in supply for item in POWER_SUPPLY_IGNORELIST) + # If found in ignore list, skip it. + if ignore_supply: continue + try: with open(Path(power_supply_path + supply + "/type")) as f: supply_type = f.read()[:-1]