From d10a241f05ee1ecb783ce84e8f0113e34ac0cf95 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 18 Aug 2026 17:09:03 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20dashboard=20showing=20"n/a"=20for=20a=20l?= =?UTF-8?q?egitimate=200.0=20=C2=B0C=20reading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit app.js gated the temperature display on `snap.temperature?.celsius` truthiness, so an exact 0 °C reading (plausible for a Pi in an unheated/outdoor enclosure) rendered as "n/a" indistinguishably from a failed sensor read. A successful reading always carries a non-empty zone, while a failed collection yields zone: "", so key off `snap.temperature?.zone` instead. Closes #64 --- internal/web/assets/app.js | 2 +- internal/web/temperature_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 internal/web/temperature_test.go diff --git a/internal/web/assets/app.js b/internal/web/assets/app.js index e0b686e..3a92f2d 100644 --- a/internal/web/assets/app.js +++ b/internal/web/assets/app.js @@ -218,7 +218,7 @@ // Temperature const tempEl = document.getElementById('temp-value'); - if (snap.temperature?.celsius) { + if (snap.temperature?.zone) { setText('temp-value', snap.temperature.celsius.toFixed(1) + ' °C'); tempEl.className = 'metric-value ' + levelClass(snap.temperature.celsius, t.temperature_warn_c, t.temperature_crit_c); } else { diff --git a/internal/web/temperature_test.go b/internal/web/temperature_test.go new file mode 100644 index 0000000..a6529cf --- /dev/null +++ b/internal/web/temperature_test.go @@ -0,0 +1,27 @@ +package web + +import ( + "strings" + "testing" +) + +// TestAppJS_TemperatureNAUsesZoneNotCelsius guards against regressing issue +// #64: a legitimate 0.0 °C reading must not render as "n/a". A failed +// collection is distinguished by an empty zone (Temperature.Zone is always +// set on a successful reading), not by the celsius value's truthiness — +// 0 is a valid, falsy reading that a `snap.temperature?.celsius` check would +// wrongly treat as missing. +func TestAppJS_TemperatureNAUsesZoneNotCelsius(t *testing.T) { + data, err := assetsFS.ReadFile("assets/app.js") + if err != nil { + t.Fatalf("read app.js: %v", err) + } + src := string(data) + + if strings.Contains(src, "snap.temperature?.celsius)") || strings.Contains(src, "snap.temperature && snap.temperature.celsius)") { + t.Errorf("app.js must not gate the temperature display on celsius truthiness (0 °C is a valid reading)") + } + if !strings.Contains(src, "snap.temperature?.zone") { + t.Errorf("expected app.js to key the temperature \"n/a\" fallback off snap.temperature?.zone") + } +}