controller: report cooling fan RPM in CPU status

The RPi 5 fan connector exposes a tachometer via the pwmfan hwmon
device. Report it as fan_rpm in cpu_stats and show it in both the
Controller fallback UI and the React Status page. Hidden when no fan
is present.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-07-23 19:42:52 -06:00 • committed by lrnselfreliance
parent f635671266
commit 42a017294e
6 changed files with 54 additions and 2 deletions

View file

@ -52,6 +52,26 @@ class TestGetCpuStatus:
assert isinstance(result["cores"], int)
assert result["cores"] > 0
def test_fan_rpm(self):
"""Fan RPM should be reported when a fan sensor exists (e.g. RPi 5 pwmfan)."""
fan = mock.Mock()
fan.current = 2599
with mock.patch("controller.lib.status.psutil.sensors_fans", create=True, return_value={"pwmfan": [fan]}):
result = get_cpu_status()
assert result["fan_rpm"] == 2599
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={}):
result = get_cpu_status()
assert result["fan_rpm"] is None
def test_fan_rpm_sensor_error(self):
"""Fan RPM should be None when the sensor read fails."""
with mock.patch("controller.lib.status.psutil.sensors_fans", create=True, side_effect=OSError("no sysfs")):
result = get_cpu_status()
assert result["fan_rpm"] is None
class TestGetMemoryStatus:
"""Tests for get_memory_status function."""