mirror of
https://github.com/AdnanHodzic/auto-cpufreq.git
synced 2025-07-23 05:34:55 +02:00
Add warnings for charge thresholds (#679)
* add warning messages to thinkpad * added warnings to laptop_acpi * added warnings to ideapad_laptop * formatted the battery output and added stats to --debug and --status * formated --stats better with battery info * removed blank lines in battery info * fixed typo: --stats battery info
This commit is contained in:
parent
f1c1dc6b10
commit
95ba1f42bd
@ -43,5 +43,3 @@ def battery_get_thresholds():
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,11 +5,12 @@ from auto_cpufreq.utils.config import config
|
|||||||
|
|
||||||
|
|
||||||
def set_battery(value, mode, bat):
|
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(
|
subprocess.check_output(
|
||||||
f"echo {value} | tee /sys/class/power_supply/BAT{bat}/charge_{mode}_threshold", shell=True, text=True)
|
f"echo {value} | tee {path}", shell=True, text=True)
|
||||||
except Exception as e:
|
else:
|
||||||
print(f"Error writing to file_path: {e}")
|
print(f"WARNING: {path} does NOT exist")
|
||||||
|
|
||||||
|
|
||||||
def get_threshold_value(mode):
|
def get_threshold_value(mode):
|
||||||
@ -33,27 +34,31 @@ def ideapad_acpi_setup():
|
|||||||
if not conf["battery"]["enable_thresholds"] == "true":
|
if not conf["battery"]["enable_thresholds"] == "true":
|
||||||
return
|
return
|
||||||
|
|
||||||
battery_count = len([name for name in os.listdir(
|
if os.path.exists("/sys/class/power_supply/"):
|
||||||
"/sys/class/power_supply/") if name.startswith('BAT')])
|
battery_count = len([name for name in os.listdir(
|
||||||
|
"/sys/class/power_supply/") if name.startswith('BAT')])
|
||||||
|
|
||||||
for bat in range(battery_count):
|
for bat in range(battery_count):
|
||||||
set_battery(get_threshold_value("start"), "start", bat)
|
set_battery(get_threshold_value("start"), "start", bat)
|
||||||
set_battery(get_threshold_value("stop"), "stop", bat)
|
set_battery(get_threshold_value("stop"), "stop", bat)
|
||||||
|
else:
|
||||||
|
print("WARNING: could NOT access /sys/class/power_supply")
|
||||||
|
|
||||||
|
|
||||||
def ideapad_acpi_print_thresholds():
|
def ideapad_acpi_print_thresholds():
|
||||||
battery_count = len([name for name in os.listdir(
|
battery_count = len([name for name in os.listdir(
|
||||||
"/sys/class/power_supply/") if name.startswith('BAT')])
|
"/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):
|
for b in range(battery_count):
|
||||||
try:
|
try:
|
||||||
with open(f'/sys/class/power_supply/BAT{b}/charge_start_threshold', 'r') as f:
|
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()
|
f.close()
|
||||||
|
|
||||||
with open(f'/sys/class/power_supply/BAT{b}/charge_stop_threshold', 'r') as f:
|
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()
|
f.close()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Error reading battery thresholds: {e}")
|
print(f"ERROR: failed to read battery {b} thresholds")
|
||||||
|
@ -5,11 +5,12 @@ from auto_cpufreq.utils.config import config
|
|||||||
|
|
||||||
|
|
||||||
def set_battery(value, mode, bat):
|
def set_battery(value, mode, bat):
|
||||||
try:
|
path = f"/sys/class/power_supply/BAT{bat}/charge_{mode}_threshold"
|
||||||
|
if os.path.exists(path):
|
||||||
subprocess.check_output(
|
subprocess.check_output(
|
||||||
f"echo {value} | tee /sys/class/power_supply/BAT{bat}/charge_{mode}_threshold", shell=True, text=True)
|
f"echo {value} | tee /sys/class/power_supply/BAT{bat}/charge_{mode}_threshold", shell=True, text=True)
|
||||||
except Exception as e:
|
else:
|
||||||
print(f"Error writing to file_path: {e}")
|
print(f"WARNING: {path} does NOT exist")
|
||||||
|
|
||||||
|
|
||||||
def get_threshold_value(mode):
|
def get_threshold_value(mode):
|
||||||
@ -84,16 +85,17 @@ def ideapad_laptop_print_thresholds():
|
|||||||
|
|
||||||
battery_count = len([name for name in os.listdir(
|
battery_count = len([name for name in os.listdir(
|
||||||
"/sys/class/power_supply/") if name.startswith('BAT')])
|
"/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):
|
for b in range(battery_count):
|
||||||
try:
|
try:
|
||||||
with open(f'/sys/class/power_supply/BAT{b}/charge_start_threshold', 'r') as f:
|
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()
|
f.close()
|
||||||
|
|
||||||
with open(f'/sys/class/power_supply/BAT{b}/charge_stop_threshold', 'r') as f:
|
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()
|
f.close()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Error reading battery thresholds: {e}")
|
print(f"ERROR: failed to read battery thresholds: {e}")
|
||||||
|
@ -5,11 +5,12 @@ from auto_cpufreq.utils.config import config
|
|||||||
|
|
||||||
|
|
||||||
def set_battery(value, mode, bat):
|
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(
|
subprocess.check_output(
|
||||||
f"echo {value} | tee /sys/class/power_supply/BAT{bat}/charge_{mode}_threshold", shell=True, text=True)
|
f"echo {value} | tee {path}", shell=True, text=True)
|
||||||
except Exception as e:
|
else:
|
||||||
print(f"Error writing to file_path: {e}")
|
print(f"WARNING: {path} does NOT exist")
|
||||||
|
|
||||||
|
|
||||||
def get_threshold_value(mode):
|
def get_threshold_value(mode):
|
||||||
@ -33,27 +34,31 @@ def thinkpad_setup():
|
|||||||
if not conf["battery"]["enable_thresholds"] == "true":
|
if not conf["battery"]["enable_thresholds"] == "true":
|
||||||
return
|
return
|
||||||
|
|
||||||
battery_count = len([name for name in os.listdir(
|
if os.path.exists("/sys/class/power_supply/"):
|
||||||
"/sys/class/power_supply/") if name.startswith('BAT')])
|
battery_count = len([name for name in os.listdir(
|
||||||
|
"/sys/class/power_supply/") if name.startswith('BAT')])
|
||||||
|
|
||||||
for bat in range(battery_count):
|
for bat in range(battery_count):
|
||||||
set_battery(get_threshold_value("start"), "start", bat)
|
set_battery(get_threshold_value("start"), "start", bat)
|
||||||
set_battery(get_threshold_value("stop"), "stop", bat)
|
set_battery(get_threshold_value("stop"), "stop", bat)
|
||||||
|
else:
|
||||||
|
print("WARNING /sys/class/power_supply/ does NOT esixt")
|
||||||
|
|
||||||
|
|
||||||
def thinkpad_print_thresholds():
|
def thinkpad_print_thresholds():
|
||||||
battery_count = len([name for name in os.listdir(
|
battery_count = len([name for name in os.listdir(
|
||||||
"/sys/class/power_supply/") if name.startswith('BAT')])
|
"/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):
|
for b in range(battery_count):
|
||||||
try:
|
try:
|
||||||
with open(f'/sys/class/power_supply/BAT{b}/charge_start_threshold', 'r') as f:
|
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()
|
f.close()
|
||||||
|
|
||||||
with open(f'/sys/class/power_supply/BAT{b}/charge_stop_threshold', 'r') as f:
|
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()
|
f.close()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(f"Error reading battery thresholds: {e}")
|
print(f"ERROR: failed to read battery {b} thresholds")
|
||||||
|
@ -154,6 +154,7 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta
|
|||||||
else:
|
else:
|
||||||
gnome_power_detect()
|
gnome_power_detect()
|
||||||
tlp_service_detect()
|
tlp_service_detect()
|
||||||
|
battery_get_thresholds()
|
||||||
read_stats()
|
read_stats()
|
||||||
elif log:
|
elif log:
|
||||||
deprecated_log_msg()
|
deprecated_log_msg()
|
||||||
@ -165,6 +166,7 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta
|
|||||||
# ToDo: add status of GNOME Power Profile service status
|
# ToDo: add status of GNOME Power Profile service status
|
||||||
config_info_dialog()
|
config_info_dialog()
|
||||||
root_check()
|
root_check()
|
||||||
|
battery_get_thresholds()
|
||||||
cpufreqctl()
|
cpufreqctl()
|
||||||
footer()
|
footer()
|
||||||
distro_info()
|
distro_info()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user