From 897664aa3ddc25c7e538608bc0da31d6fb822086 Mon Sep 17 00:00:00 2001 From: AmitGolden <39828974+AmitGolden@users.noreply.github.com> Date: Fri, 19 Nov 2021 09:08:32 +0200 Subject: [PATCH] Fix instances where charging is not recognized (#281) (#285) * check if charging in laptop with battery * using both battery and ac adapter to check if charging also battery status unknown is now recognized as charging --- auto_cpufreq/core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index 3d1c90e..f82d527 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -168,10 +168,13 @@ def charging(): computer_type = getoutput("dmidecode --string chassis-type") if computer_type in ["Notebook", "Laptop", "Convertible", "Portable"]: + # AC adapter states: 0, 1, unknown + ac_info = getoutput(f"grep . {power_dir}A*/online").splitlines() # Battery statuses: Full, Charging, Discharging, Unknown battery_status = getoutput(f"grep . {power_dir}B*/status").splitlines() - # if there's one battery charging, ac_state is True - ac_state = any(["Full" in ac or "Charging" in ac for ac in battery_status]) + # if there's one battery charging, or if there's one ac-adapter on-line, ac_state is True + ac_state = (any([not "Discharging" in ac for ac in battery_status]) or + any(["1" in ac.split(":")[-1] for ac in ac_info])) else: has_battery = psutil.sensors_battery() is not None if has_battery: