From c99b610b985245f7d0a8b5aa7120914d6ffbc50c Mon Sep 17 00:00:00 2001 From: Bryan Malyn Date: Thu, 16 Feb 2023 20:59:24 -0600 Subject: [PATCH] Add thermometer progression --- src/blocks.rs | 10 ++++++++++ src/blocks/temperature.rs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/blocks.rs b/src/blocks.rs index 2a08012642..26ff678545 100644 --- a/src/blocks.rs +++ b/src/blocks.rs @@ -333,6 +333,16 @@ impl CommonApi { .or_error(|| format!("Icon '{icon}' not found")) } + pub fn get_icon_in_progression_bound( + &self, + icon: &str, + value: f64, + low: f64, + high: f64, + ) -> Result { + self.get_icon_in_progression(icon, (value.clamp(low, high) - low) / (high - low)) + } + /// Repeatedly call provided async function until it succeeds. /// /// This function will call `f` in a loop. If it succeeds, the result will be returned. diff --git a/src/blocks/temperature.rs b/src/blocks/temperature.rs index c162434d0b..e1521b32c0 100644 --- a/src/blocks/temperature.rs +++ b/src/blocks/temperature.rs @@ -191,7 +191,7 @@ pub async fn run(config: Config, mut api: CommonApi) -> Result<()> { }; widget.set_values(map! { - "icon" => Value::icon(api.get_icon("thermometer")?), + "icon" => Value::icon(api.get_icon_in_progression_bound("thermometer", max_temp, good, warn)?), "average" => Value::degrees(avg_temp), "min" => Value::degrees(min_temp), "max" => Value::degrees(max_temp),