From 1a88fb4a5b91c921fd55ede03a55c069a716e0b1 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 23 Jul 2026 19:47:51 -0600 Subject: [PATCH] controller: report idle (0 RPM) fans; prefer the CPU fan over case fans The RPi 5 firmware stops the fan entirely when cool, so a 0 RPM reading is normal and must not be hidden. On multi-fan machines, prefer a CPU-labeled hwmon group over faster case fans. Co-Authored-By: Claude Fable 5 --- controller/lib/status.py | 4 +++- controller/templates/index.html | 4 ++-- controller/test/test_status.py | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/controller/lib/status.py b/controller/lib/status.py index 9541ea61..f6b47dc6 100644 --- a/controller/lib/status.py +++ b/controller/lib/status.py @@ -97,7 +97,9 @@ def get_cpu_status() -> dict: fan_rpm = None try: fans = psutil.sensors_fans() if hasattr(psutil, "sensors_fans") else {} - readings = [i.current for readings_ in fans.values() for i in readings_ if i.current] + # Prefer a CPU-labeled fan when several fan groups exist; 0 RPM is a valid reading (idle fan). + cpu_fans = {k: v for k, v in fans.items() if k == "pwmfan" or "cpu" in k.lower()} + readings = [i.current for group in (cpu_fans or fans).values() for i in group if i.current is not None] if readings: fan_rpm = int(max(readings)) except Exception: diff --git a/controller/templates/index.html b/controller/templates/index.html index 5a9c192e..fd2f872a 100644 --- a/controller/templates/index.html +++ b/controller/templates/index.html @@ -938,7 +938,7 @@

CPU

{{ cpu.percent if cpu.percent is not none else '--' }}%

-

{% if cpu.temperature_c %}{{ cpu.temperature_c }}°C{% else %}--{% endif %}{% if cpu.fan_rpm %} · {{ cpu.fan_rpm }} RPM{% endif %}

+

{% if cpu.temperature_c %}{{ cpu.temperature_c }}°C{% else %}--{% endif %}{% if cpu.fan_rpm is not none %} · {{ cpu.fan_rpm }} RPM{% endif %}

Memory

@@ -2694,7 +2694,7 @@ if (cpuValue) cpuValue.textContent = (cpu.percent !== null ? cpu.percent : '--') + '%'; if (cpuSub) { let cpuSubText = cpu.temperature ? cpu.temperature + '°C' : '--'; - if (cpu.fan_rpm) { + if (cpu.fan_rpm !== null && cpu.fan_rpm !== undefined) { cpuSubText += ' · ' + cpu.fan_rpm + ' RPM'; } cpuSub.innerHTML = cpuSubText; diff --git a/controller/test/test_status.py b/controller/test/test_status.py index 34f62af8..2e954a32 100644 --- a/controller/test/test_status.py +++ b/controller/test/test_status.py @@ -60,6 +60,25 @@ class TestGetCpuStatus: result = get_cpu_status() assert result["fan_rpm"] == 2599 + def test_fan_rpm_zero_is_reported(self): + """A stopped/idle fan (0 RPM) should be reported, not hidden (RPi 5 stops its fan when cool).""" + fan = mock.Mock() + fan.current = 0 + with mock.patch("controller.lib.status.psutil.sensors_fans", create=True, return_value={"pwmfan": [fan]}): + result = get_cpu_status() + assert result["fan_rpm"] == 0 + + def test_fan_rpm_prefers_cpu_fan(self): + """When multiple fan groups exist, the CPU fan should be preferred over faster case fans.""" + cpu_fan = mock.Mock() + cpu_fan.current = 1200 + case_fan = mock.Mock() + case_fan.current = 3000 + fans = {"dell_smm_cpu": [cpu_fan], "case": [case_fan]} + with mock.patch("controller.lib.status.psutil.sensors_fans", create=True, return_value=fans): + result = get_cpu_status() + assert result["fan_rpm"] == 1200 + def test_fan_rpm_no_fan(self): """Fan RPM should be None when no fan sensor exists.""" with mock.patch("controller.lib.status.psutil.sensors_fans", create=True, return_value={}):