use psutil for cpu temp (#200)
This commit is contained in:
@@ -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
|
|
||||||
|
cpu_temp = temps["coretemp"][0].current
|
||||||
return cpu_temp
|
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():
|
||||||
|
|||||||
Reference in New Issue
Block a user