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 @@ -43,5 +43,3 @@ def battery_get_thresholds():

else:
return


33 changes: 19 additions & 14 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,27 +34,31 @@ def ideapad_acpi_setup():
if not conf["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():
battery_count = len([name for name in os.listdir(
"/sys/class/power_supply/") if name.startswith('BAT')])
print(f"number of batteries = {battery_count}")
print("\n-------------------------------- Battery Info ---------------------------------\n")
print(f"battery count = {battery_count}")
for b in range(battery_count):
try:
with open(f'/sys/class/power_supply/BAT{b}/charge_start_threshold', 'r') as f:
print(f'battery{b} start threshold is set to {f.read()}')
print(f'battery{b} start threshold = {f.read()}', end="")
f.close()

with open(f'/sys/class/power_supply/BAT{b}/charge_stop_threshold', 'r') as f:
print(f'battery{b} stop threshold is set to {f.read()}')
print(f'battery{b} stop threshold = {f.read()}', end="")
f.close()

except Exception as e:
print(f"Error reading battery thresholds: {e}")
except Exception:
print(f"ERROR: failed to read battery {b} thresholds")
18 changes: 10 additions & 8 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 Expand Up @@ -84,16 +85,17 @@ def ideapad_laptop_print_thresholds():

battery_count = len([name for name in os.listdir(
"/sys/class/power_supply/") if name.startswith('BAT')])
print(f"number of batteries = {battery_count}")
print("\n-------------------------------- Battery Info ---------------------------------\n")
print(f"battery count = {battery_count}")
for b in range(battery_count):
try:
with open(f'/sys/class/power_supply/BAT{b}/charge_start_threshold', 'r') as f:
print(f'battery{b} start threshold is set to {f.read()}')
print(f'battery{b} start threshold = {f.read()}', end="")
f.close()

with open(f'/sys/class/power_supply/BAT{b}/charge_stop_threshold', 'r') as f:
print(f'battery{b} stop threshold is set to {f.read()}')
print(f'battery{b} stop threshold = {f.read()}', end="")
f.close()

except Exception as e:
print(f"Error reading battery thresholds: {e}")
except Exception:
print(f"ERROR: failed to read battery thresholds: {e}")
33 changes: 19 additions & 14 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,27 +34,31 @@ def thinkpad_setup():
if not conf["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():
battery_count = len([name for name in os.listdir(
"/sys/class/power_supply/") if name.startswith('BAT')])
print(f"number of batteries = {battery_count}")
print("\n-------------------------------- Battery Info ---------------------------------\n")
print(f"battery count = {battery_count}")
for b in range(battery_count):
try:
with open(f'/sys/class/power_supply/BAT{b}/charge_start_threshold', 'r') as f:
print(f'battery{b} start threshold is set to {f.read()}')
print(f'battery{b} start threshold = {f.read()}', end="")
f.close()

with open(f'/sys/class/power_supply/BAT{b}/charge_stop_threshold', 'r') as f:
print(f'battery{b} stop threshold is set to {f.read()}')
print(f'battery{b} stop threshold = {f.read()}', end="")
f.close()

except Exception as e:
print(f"Error reading battery thresholds: {e}")
except Exception:
print(f"ERROR: failed to read battery {b} thresholds")
2 changes: 2 additions & 0 deletions auto_cpufreq/bin/auto_cpufreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def config_info_dialog():
else:
gnome_power_detect()
tlp_service_detect()
battery_get_thresholds()
read_stats()
elif log:
deprecated_log_msg()
Expand All @@ -165,6 +166,7 @@ def config_info_dialog():
# ToDo: add status of GNOME Power Profile service status
config_info_dialog()
root_check()
battery_get_thresholds()
cpufreqctl()
footer()
distro_info()
Expand Down