use psutil for cpu temp (#200)

This commit is contained in:
Masoko
2025-03-23 18:39:14 +02:00
committed by GitHub
parent 850c57d872
commit 8634179c31

View File

@@ -160,14 +160,16 @@ def read_ext_sensors():
def check_cpu_temp(): def check_cpu_temp():
full_cmd = f"awk '{{printf (\"%.2f\\n\", $1/1000); }}' $(for zone in /sys/class/thermal/thermal_zone*/; do grep -iq \"{config.cpu_thermal_zone}\" \"${{zone}}type\" && echo \"${{zone}}temp\"; done)"
try: try:
p = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] temps = psutil.sensors_temperatures()
cpu_temp = p.decode("utf-8").strip().replace(",", ".") if not temps or "coretemp" not in temps:
except Exception: raise ValueError("CPU temperature sensor not found.")
cpu_temp = None if config.use_availability else 0
return cpu_temp cpu_temp = temps["coretemp"][0].current
return round(cpu_temp, 2)
except Exception as e:
print(f"Error reading CPU temperature: {e}")
return None if config.use_availability else 0
def check_sys_clock_speed(): def check_sys_clock_speed():