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:
|
||||
return
|
||||
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@ from auto_cpufreq.utils.config import config
|
|||
|
||||
|
||||
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):
|
||||
|
@ -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")
|
||||
|
|
|
@ -5,11 +5,12 @@ from auto_cpufreq.utils.config import config
|
|||
|
||||
|
||||
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(
|
||||
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):
|
||||
|
@ -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}")
|
||||
|
|
|
@ -5,11 +5,12 @@ from auto_cpufreq.utils.config import config
|
|||
|
||||
|
||||
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):
|
||||
|
@ -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")
|
||||
|
|
|
@ -154,6 +154,7 @@ def main(config, daemon, debug, update, install, remove, live, log, monitor, sta
|
|||
else:
|
||||
gnome_power_detect()
|
||||
tlp_service_detect()
|
||||
battery_get_thresholds()
|
||||
read_stats()
|
||||
elif log:
|
||||
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
|
||||
config_info_dialog()
|
||||
root_check()
|
||||
battery_get_thresholds()
|
||||
cpufreqctl()
|
||||
footer()
|
||||
distro_info()
|
||||
|
|
Loading…
Reference in New Issue