From d651b34ace98a901d542cb465e830c7542fd9ef3 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Fri, 30 Jun 2023 23:21:42 -0400 Subject: [PATCH] Made cpu.py discover /sys node containing temperature. --- owrx/cpu.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/owrx/cpu.py b/owrx/cpu.py index 339ebda4..61629c90 100644 --- a/owrx/cpu.py +++ b/owrx/cpu.py @@ -2,6 +2,8 @@ from owrx.config.core import CoreConfig import threading import os.path +import os +import re import logging @@ -26,18 +28,38 @@ class CpuUsageThread(threading.Thread): self.last_idletime = 0 # Determine where to read CPU temperature from - tempFile0 = CoreConfig().get_temperature_sensor() - tempFile1 = "/sys/class/thermal/thermal_zone0/temp" - tempFile2 = "/sys/class/hwmon/hwmon0/device/temp" - if tempFile0 is not None and os.path.isfile(tempFile0): - self.tempFile = tempFile0 - elif os.path.isfile(tempFile1): - self.tempFile = tempFile1 - elif os.path.isfile(tempFile2): - self.tempFile = tempFile2 + tempFile = CoreConfig().get_temperature_sensor() + if tempFile is not None and os.path.isfile(tempFile): + self.tempFile = tempFile else: self.tempFile = None + # Check sensors in /sys/class/thermal + if self.tempFile is None: + tempRoot = "/sys/class/thermal" + try: + for file in os.listdir(tempRoot): + if re.match(r"thermal_zone\d+", file): + tempFile = tempRoot + "/" + file + "/temp" + if os.path.isfile(tempFile): + self.tempFile = tempFile + break + except Exception: + pass + + # Check monitors in /sys/class/hwmon + if self.tempFile is None: + tempRoot = "/sys/class/hwmon" + try: + for file in os.listdir(tempRoot): + if re.match(r"hwmon\d+", file): + tempFile = tempRoot + "/" + file + "/device/temp" + if os.path.isfile(tempFile): + self.tempFile = tempFile + break + except Exception: + pass + self.endEvent = threading.Event() self.startLock = threading.Lock() super().__init__()