터치 패널 디스크 온도 캐시 분리
This commit is contained in:
1 parent
11e29d9954
commit
cfd5bb9b94
4 files changed
+104
-18
No files matched your search
+22
-17
@@ -112,6 +112,8 @@ TEMP_GRAPH_POINTS = TEMP_GRAPH_SECONDS * 1000 // DASHBOARD_INTERVAL_MS
|
||||
SYNOLOGY_RESTART_INTERVAL_MS = 1000
|
||||
TEMP_INTERVAL_MS = 500
|
||||
DISK_TEMP_INTERVAL_MS = TEMP_INTERVAL_MS
|
||||
DISK_TEMP_CACHE_FILE = "/run/control-rpi-disk-temp"
|
||||
DISK_TEMP_CACHE_MAX_AGE_SECONDS = 30
|
||||
RPI_THROTTLE_INTERVAL_MS = SAMPLE_INTERVAL_MS
|
||||
SYNOLOGY_DISK_TEMP_INTERVAL_MS = TEMP_INTERVAL_MS
|
||||
SYNOLOGY_HEALTH_INTERVAL_MS = FAN_INTERVAL_MS
|
||||
@@ -171,6 +173,25 @@ def cpu_temp():
|
||||
return round(raw / 1000, 1) if raw > 0 else 0.0
|
||||
|
||||
|
||||
def cached_disk_temp():
|
||||
values = {}
|
||||
for line in read_text(DISK_TEMP_CACHE_FILE).splitlines():
|
||||
if "=" not in line:
|
||||
continue
|
||||
key, value = line.split("=", 1)
|
||||
values[key.strip()] = value.strip()
|
||||
|
||||
try:
|
||||
updated = float(values.get("UPDATED", "0") or 0)
|
||||
temp = float(values.get("TEMP", ""))
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
if updated <= 0 or (time.time() - updated) > DISK_TEMP_CACHE_MAX_AGE_SECONDS:
|
||||
return None
|
||||
return temp
|
||||
|
||||
|
||||
def fan_paths():
|
||||
for pwm in Path("/sys/devices/platform/cooling_fan/hwmon").glob("hwmon*/pwm1"):
|
||||
base = pwm.parent
|
||||
@@ -609,8 +630,6 @@ class TouchPanel(QMainWindow):
|
||||
self.pc_timer.timeout.connect(self.ping_pc)
|
||||
self.pc_timer.start(1000)
|
||||
|
||||
self.disk_temp_proc = QProcess(self)
|
||||
self.disk_temp_proc.finished.connect(self.disk_temp_finished)
|
||||
self.disk_temp_timer = QTimer(self)
|
||||
self.disk_temp_timer.timeout.connect(self.update_disk_temp)
|
||||
self.disk_temp_timer.start(DISK_TEMP_INTERVAL_MS)
|
||||
@@ -913,22 +932,8 @@ class TouchPanel(QMainWindow):
|
||||
|
||||
def update_disk_temp(self):
|
||||
self.latest_temp = cpu_temp()
|
||||
self.disk_temp = cached_disk_temp()
|
||||
self.render_rpi_temp(self.latest_temp)
|
||||
if self.disk_temp_proc.state() != QProcess.NotRunning:
|
||||
return
|
||||
self.disk_temp_proc.start("/usr/bin/sudo", ["-n", "/usr/sbin/smartctl", "-A", "-d", "sntasmedia", "/dev/sda"])
|
||||
|
||||
def disk_temp_finished(self, exit_code, exit_status):
|
||||
del exit_code, exit_status
|
||||
output = bytes(self.disk_temp_proc.readAllStandardOutput()).decode("utf-8", "ignore")
|
||||
for line in output.splitlines():
|
||||
if line.strip().startswith("Temperature:"):
|
||||
parts = line.split()
|
||||
for part in parts:
|
||||
if part.isdigit():
|
||||
self.disk_temp = float(part)
|
||||
self.render_rpi_temp(getattr(self, "latest_temp", 0.0))
|
||||
return
|
||||
|
||||
def update_synology_status(self):
|
||||
if self.synology_proc.state() != QProcess.NotRunning:
|
||||
|
||||
Reference in new issue
Block a user