터치 패널 디스크 온도 캐시 분리

This commit is contained in:
seo committed 2026-08-02 00:45:36 +09:00
1 parent 11e29d9954
commit cfd5bb9b94
4 files changed
+104 -18

No files matched your search

+22 -17
View File
@@ -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:
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
import os
import re
import subprocess
import time
from pathlib import Path
CACHE_FILE = Path("/run/control-rpi-disk-temp")
DISK = "/dev/sda"
INTERVAL_SECONDS = 5
SMARTCTL = "/usr/sbin/smartctl"
def parse_temp(output):
for line in output.splitlines():
stripped = line.strip()
if stripped.startswith("Temperature:"):
match = re.search(r"([0-9]+(?:\.[0-9]+)?)", stripped)
if match:
return float(match.group(1))
if "Temperature_Celsius" in stripped or "Airflow_Temperature_Cel" in stripped:
parts = stripped.split()
for part in reversed(parts):
if part.isdigit():
return float(part)
return None
def read_temp():
result = subprocess.run(
[SMARTCTL, "-A", "-d", "sntasmedia", DISK],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
text=True,
timeout=4,
check=False,
)
if result.returncode not in (0, 4, 64):
return None
return parse_temp(result.stdout)
def write_cache(temp):
tmp = CACHE_FILE.with_suffix(".tmp")
if temp is None:
content = f"UPDATED={time.time():.3f}\nTEMP=\nOK=0\n"
else:
content = f"UPDATED={time.time():.3f}\nTEMP={temp:.1f}\nOK=1\n"
tmp.write_text(content, encoding="utf-8")
os.replace(tmp, CACHE_FILE)
os.chmod(CACHE_FILE, 0o644)
def main():
while True:
try:
write_cache(read_temp())
except Exception:
write_cache(None)
time.sleep(INTERVAL_SECONDS)
if __name__ == "__main__":
main()