From d7941e848cf1c68ca505b5640499e15b267bb25f Mon Sep 17 00:00:00 2001 From: PurpleWazard <155469001+PurpleWazard@users.noreply.github.com> Date: Sun, 7 Sep 2025 12:05:53 -0500 Subject: [PATCH] ASUS laptop to battery thresholds. (#875) * added asus battery support * asus added to readme --- README.md | 1 + auto_cpufreq/battery_scripts/asus.py | 39 +++++++++++++++++++++++++ auto_cpufreq/battery_scripts/battery.py | 3 ++ 3 files changed, 43 insertions(+) create mode 100644 auto_cpufreq/battery_scripts/asus.py diff --git a/README.md b/README.md index 9c0ac6e..3be610e 100644 --- a/README.md +++ b/README.md @@ -595,6 +595,7 @@ As of [v2.2.0](https://github.com/AdnanHodzic/auto-cpufreq/releases/tag/v2.2.0), - **Lenovo ThinkPad** (thinkpad_acpi)* - **Lenovo IdeaPad** (ideapad_acpi)* +- **ASUS :Laptops** (asus_wmi)* ***Please note, your laptop must have an installed ACPI kernel driver specific to the manufacturer.** To check if you have the correct module installed and loaded run `lsmod [module]` diff --git a/auto_cpufreq/battery_scripts/asus.py b/auto_cpufreq/battery_scripts/asus.py new file mode 100644 index 0000000..58b4944 --- /dev/null +++ b/auto_cpufreq/battery_scripts/asus.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import os +from subprocess import check_output + +from auto_cpufreq.config.config import config +from auto_cpufreq.globals import POWER_SUPPLY_DIR + +def set_battery(value, mode, bat): + path = f"{POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold" + if os.path.isfile(path): check_output(f"echo {value} | tee {path}", shell=True, text=True) + else: print(f"WARNING: {path} does NOT exist") + +def get_threshold_value(mode): + conf = config.get_config() + return conf["battery"][f"{mode}_threshold"] if conf.has_option("battery", f"{mode}_threshold") else (0 if mode == "start" else 100) + +def asus_setup(): + conf = config.get_config() + + if not (conf.has_option("battery", "enable_thresholds") and conf["battery"]["enable_thresholds"] == "true"): return + + if os.path.exists(POWER_SUPPLY_DIR): + batteries = [name for name in os.listdir(POWER_SUPPLY_DIR) if name.startswith('BAT')] + + for bat in batteries: + set_battery(get_threshold_value("start"), "start", bat) + set_battery(get_threshold_value("stop"), "stop", bat) + else: print(f"WARNING {POWER_SUPPLY_DIR} does NOT esixt") + + +def asus_print_thresholds(): + batteries = [name for name in os.listdir(POWER_SUPPLY_DIR) if name.startswith('BAT')] + print("\n-------------------------------- Battery Info ---------------------------------\n") + print(f"battery count = {len(batteries)}") + for bat in batteries: + try: + print(bat, "start threshold =", check_output(["cat", POWER_SUPPLY_DIR+bat+"/charge_start_threshold"])) + print(bat, "stop threshold =", check_output(["cat", POWER_SUPPLY_DIR+bat+"/charge_stop_threshold"])) + except Exception as e: print(f"ERROR: failed to read battery {bat} thresholds:", repr(e)) diff --git a/auto_cpufreq/battery_scripts/battery.py b/auto_cpufreq/battery_scripts/battery.py index cbec71a..35ceb43 100644 --- a/auto_cpufreq/battery_scripts/battery.py +++ b/auto_cpufreq/battery_scripts/battery.py @@ -4,6 +4,7 @@ from subprocess import PIPE, run from auto_cpufreq.battery_scripts.ideapad_acpi import ideapad_acpi_print_thresholds, ideapad_acpi_setup from auto_cpufreq.battery_scripts.ideapad_laptop import ideapad_laptop_print_thresholds, ideapad_laptop_setup from auto_cpufreq.battery_scripts.thinkpad import thinkpad_print_thresholds, thinkpad_setup +from auto_cpufreq.battery_scripts.asus import asus_print_thresholds, asus_setup def lsmod(module): return module in run(['lsmod'], stdout=PIPE, stderr=PIPE, text=True, shell=True).stdout @@ -11,10 +12,12 @@ def battery_get_thresholds(): if lsmod("ideapad_acpi"): ideapad_acpi_print_thresholds() elif lsmod("ideapad_laptop"): ideapad_laptop_print_thresholds() elif lsmod("thinkpad_acpi"): thinkpad_print_thresholds() + elif lsmod("asus_wmi"): asus_print_thresholds() else: return def battery_setup(): if lsmod("ideapad_acpi"): ideapad_acpi_setup() elif lsmod("ideapad_laptop"): ideapad_laptop_setup() elif lsmod("thinkpad_acpi"): thinkpad_setup() + elif lsmod("asus_wmi"): asus_setup() else: return