Updating many thermal and status things

This commit is contained in:
2023-12-31 16:44:44 -05:00
parent a500a63a53
commit dc30944a89
4 changed files with 157 additions and 76 deletions
+30 -24
View File
@@ -1,16 +1,18 @@
#!/usr/bin/env python
import json
import os
import shutil
import subprocess
import sys
import typing
__all__ = ["_mem", "_backlight", "_hwtemp"]
_BITS = []
_BITS: list[tuple[int, str, typing.Callable]] = []
def _bit(idx):
def wrapper(func):
_BITS.append([idx, func.__name__.replace("_", ""), func])
_BITS.append((idx, func.__name__.replace("_", ""), func))
return func
return wrapper
@@ -49,29 +51,39 @@ def _backlight(dev_dir="/sys/class/backlight/intel_backlight"):
return "☼:{}%".format(pct), color
THINKFAN_CONF = "/etc/thinkfan.conf"
ACPI_IBM_FAN = "/proc/acpi/ibm/fan"
@_bit(7)
def _hwtemp(conf=THINKFAN_CONF, fan=ACPI_IBM_FAN):
if not os.path.exists(conf):
def _hwtemp(fan=ACPI_IBM_FAN):
acpi_exe = shutil.which("acpi")
if acpi_exe is None:
return None, None
temps = []
raw_temp = subprocess.run(
[acpi_exe, "-t"],
text=True,
capture_output=True,
check=False,
)
if raw_temp.returncode != 0 or raw_temp.stdout is None:
return None, None
with open("/etc/thinkfan.conf") as tfc_fp:
for line in tfc_fp.readlines():
if not line.startswith("hwmon "):
continue
try:
with open(line.split(" ")[1].strip()) as temp_fp:
temps.append(float(temp_fp.read()))
except (OSError, IOError) as exc:
sys.stderr.write(str(exc) + "\n")
temps_by_zone = {}
for line in raw_temp.stdout.splitlines():
zone_id, value = line.split(":")
human_temp = value.split(",")[-1]
temps_by_zone[zone_id.lower().lstrip("thermal ")] = float(
human_temp.lower().strip().rstrip("degrees c")
)
avg_temp = float(sum(temps)) / len(temps) / 1000.0
color = None
temps = list(temps_by_zone.values())
avg_temp = float(sum(temps)) / len(temps)
color = "#5599ff"
if avg_temp > 75:
color = "#ff0000"
if avg_temp >= 50:
color = "#ffaa00"
fan_level = "unset"
try:
@@ -83,12 +95,6 @@ def _hwtemp(conf=THINKFAN_CONF, fan=ACPI_IBM_FAN):
except (OSError, IOError) as exc:
sys.stderr.write(str(exc) + "\n")
if avg_temp > 75:
color = "#ff0000"
if avg_temp >= 50:
color = "#ffaa00"
if avg_temp <= 25:
color = "#5599ff"
return "T:{:.1f}°C L:{}".format(avg_temp, fan_level), color