From 29bfe4129faf564e3423b914fc122f0b841f2b7b Mon Sep 17 00:00:00 2001 From: Gioele De Vitti Date: Thu, 5 Jan 2023 19:16:47 +0000 Subject: [PATCH] Fix temperature values not being accessible due to NaN values (#650) * Fix NaN values making JSON not accessible * Explain NaN replacement * Report fix in changelog --- CHANGELOG.md | 1 + crates/eww/src/config/system_stats.rs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c6daac..5c7ba21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Fix deflisten scripts not always getting cleaned up properly - Add `:round-digits` to scale widget (By: gavynriebau) - Fix cirular-progress not properly displaying 100% values when clockwise is false +- Fix temperatures inside `EWW_TEMPS` not being accessible if at least one value is `NaN` ## 0.3.0 (26.05.2022) diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index 191fe57..3ba426d 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -60,7 +60,13 @@ pub fn get_temperatures() -> String { "{{ {} }}", c.components() .iter() - .map(|c| format!(r#""{}": {}"#, c.label().to_uppercase().replace(' ', "_"), c.temperature())) + .map(|c| format!( + r#""{}": {}"#, + c.label().to_uppercase().replace(' ', "_"), + // It is common for temperatures to report a non-numeric value. + // Tolerate it by serializing it as the string "null" + c.temperature().to_string().replace("NaN", "\"null\"") + )) .join(",") ) }