From b36ba34f8945f376683ba29a6c80b2859982005f 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 130473f098..d16b18682d 100644 --- a/src/blocks.rs +++ b/src/blocks.rs @@ -246,6 +246,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 6e8a62f4b6..51c7af1c7e 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<()> { 'outer: loop { 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),