Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add warnings for charge thresholds #679

Merged
merged 8 commits into from
May 9, 2024
Merged
2 changes: 0 additions & 2 deletions auto_cpufreq/battery_scripts/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,3 @@ def battery_get_thresholds():

else:
return


22 changes: 13 additions & 9 deletions auto_cpufreq/battery_scripts/ideapad_acpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@


def set_battery(value, mode, bat):
try:
path = f"/sys/class/power_supply/BAT{bat}/charge_{mode}_threshold"
if os.path.isfile(path):
subprocess.check_output(
f"echo {value} | tee /sys/class/power_supply/BAT{bat}/charge_{mode}_threshold", shell=True, text=True)
except Exception as e:
print(f"Error writing to file_path: {e}")
f"echo {value} | tee {path}", shell=True, text=True)
else:
print(f"WARNING: {path} does NOT exist")


def get_threshold_value(mode):
Expand All @@ -33,12 +34,15 @@ def ideapad_acpi_setup():
if not config["battery"]["enable_thresholds"] == "true":
return

battery_count = len([name for name in os.listdir(
"/sys/class/power_supply/") if name.startswith('BAT')])
if os.path.exists("/sys/class/power_supply/"):
battery_count = len([name for name in os.listdir(
"/sys/class/power_supply/") if name.startswith('BAT')])

for bat in range(battery_count):
set_battery(get_threshold_value("start"), "start", bat)
set_battery(get_threshold_value("stop"), "stop", bat)
for bat in range(battery_count):
set_battery(get_threshold_value("start"), "start", bat)
set_battery(get_threshold_value("stop"), "stop", bat)
else:
print("WARNING: could NOT access /sys/class/power_supply")


def ideapad_acpi_print_thresholds():
Expand Down
7 changes: 4 additions & 3 deletions auto_cpufreq/battery_scripts/ideapad_laptop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@


def set_battery(value, mode, bat):
try:
path = f"/sys/class/power_supply/BAT{bat}/charge_{mode}_threshold"
if os.path.exists(path):
PurpleWazard marked this conversation as resolved.
Show resolved Hide resolved
subprocess.check_output(
f"echo {value} | tee /sys/class/power_supply/BAT{bat}/charge_{mode}_threshold", shell=True, text=True)
except Exception as e:
print(f"Error writing to file_path: {e}")
else:
print(f"WARNING: {path} does NOT exist")


def get_threshold_value(mode):
Expand Down
22 changes: 13 additions & 9 deletions auto_cpufreq/battery_scripts/thinkpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@


def set_battery(value, mode, bat):
try:
path = f"/sys/class/power_supply/BAT{bat}/charge_{mode}_threshold"
if os.path.isfile(path):
subprocess.check_output(
f"echo {value} | tee /sys/class/power_supply/BAT{bat}/charge_{mode}_threshold", shell=True, text=True)
except Exception as e:
print(f"Error writing to file_path: {e}")
f"echo {value} | tee {path}", shell=True, text=True)
else:
print(f"WARNING: {path} does NOT exist")


def get_threshold_value(mode):
Expand All @@ -33,12 +34,15 @@ def thinkpad_setup():
if not config["battery"]["enable_thresholds"] == "true":
return

battery_count = len([name for name in os.listdir(
"/sys/class/power_supply/") if name.startswith('BAT')])
if os.path.exists("/sys/class/power_supply/"):
battery_count = len([name for name in os.listdir(
"/sys/class/power_supply/") if name.startswith('BAT')])

for bat in range(battery_count):
set_battery(get_threshold_value("start"), "start", bat)
set_battery(get_threshold_value("stop"), "stop", bat)
for bat in range(battery_count):
set_battery(get_threshold_value("start"), "start", bat)
set_battery(get_threshold_value("stop"), "stop", bat)
else:
print("WARNING /sys/class/power_supply/ does NOT esixt")


def thinkpad_print_thresholds():
Expand Down