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
This commit is contained in:
Gioele De Vitti 2023-01-05 19:16:47 +00:00 committed by GitHub
parent 3ae34602eb
commit 29bfe4129f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -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 - Fix deflisten scripts not always getting cleaned up properly
- Add `:round-digits` to scale widget (By: gavynriebau) - Add `:round-digits` to scale widget (By: gavynriebau)
- Fix cirular-progress not properly displaying 100% values when clockwise is false - 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) ## 0.3.0 (26.05.2022)

View file

@ -60,7 +60,13 @@ pub fn get_temperatures() -> String {
"{{ {} }}", "{{ {} }}",
c.components() c.components()
.iter() .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(",") .join(",")
) )
} }