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

Show error message if threshold file doesn't exist #742

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions auto_cpufreq/battery_scripts/ideapad_acpi.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python3
import os, subprocess
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): subprocess.check_output(f"echo {value} | tee {path}", shell=True, text=True)
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):
Expand All @@ -32,6 +33,6 @@ def ideapad_acpi_print_thresholds():
print(f"battery count = {len(batteries)}")
for bat in batteries:
try:
print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_start_threshold")}')
print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_stop_threshold")}')
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))
13 changes: 7 additions & 6 deletions auto_cpufreq/battery_scripts/ideapad_laptop.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python3
import os, subprocess
import os
from subprocess import check_output

from auto_cpufreq.config.config import config
from auto_cpufreq.globals import CONSERVATION_MODE_FILE, POWER_SUPPLY_DIR

def set_battery(value, mode, bat):
path = f"{POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold"
if os.path.exists(path):
subprocess.check_output(f"echo {value} | tee {POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold", shell=True, text=True)
check_output(f"echo {value} | tee {POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold", shell=True, text=True)
else: print(f"WARNING: {path} does NOT exist")

def get_threshold_value(mode):
Expand All @@ -16,14 +17,14 @@ def get_threshold_value(mode):

def conservation_mode(value):
try:
subprocess.check_output(f"echo {value} | tee {CONSERVATION_MODE_FILE}", shell=True, text=True)
check_output(f"echo {value} | tee {CONSERVATION_MODE_FILE}", shell=True, text=True)
print(f"conservation_mode is {value}")
except: print("unable to set conservation mode")
return

def check_conservation_mode():
try:
value = subprocess.check_output(["cat", CONSERVATION_MODE_FILE], text=True)
value = check_output(["cat", CONSERVATION_MODE_FILE], text=True)
if value == "1": return True
elif value == "0": return False
else:
Expand Down Expand Up @@ -63,6 +64,6 @@ def ideapad_laptop_print_thresholds():
print(f"battery count = {len(batteries)}")
for bat in batteries:
try:
print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_start_threshold")}')
print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_stop_threshold")}')
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))
9 changes: 5 additions & 4 deletions auto_cpufreq/battery_scripts/thinkpad.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python3
import os, subprocess
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): subprocess.check_output(f"echo {value} | tee {path}", shell=True, text=True)
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):
Expand All @@ -33,6 +34,6 @@ def thinkpad_print_thresholds():
print(f"battery count = {len(batteries)}")
for bat in batteries:
try:
print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_start_threshold")}')
print(f'{bat} start threshold = {subprocess.getoutput(f"cat {POWER_SUPPLY_DIR}{bat}/charge_stop_threshold")}')
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))