From c2b4ab9383567828703dd1807692fc4234f27a7d Mon Sep 17 00:00:00 2001 From: Xiretza Date: Fri, 26 Jan 2024 21:07:45 +0000 Subject: [PATCH] Don't require spaceapi to be available immediately on startup Important because homeassistant is slow as hell --- src/bot.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 2e7a701..7ace3c2 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -89,7 +89,7 @@ pub struct Bot { client: Client, api: ItsApi, - open_state: Mutex, + open_state: Mutex>, } impl Bot { @@ -123,7 +123,7 @@ impl Bot { config.space.spaceping_url.clone(), config.space.spaceping_token.clone(), ); - let open_state = get_open_state(&api).await?; + let open_state = get_open_state(&api).await.ok(); Ok(Self { config, @@ -146,7 +146,7 @@ impl Bot { #[instrument(skip(self))] async fn update_open_state(&self) -> Result { let new_state = get_open_state(&self.api).await?; - if new_state != *self.open_state.lock().unwrap() { + if *self.open_state.lock().unwrap() != Some(new_state) { let message = if let OpenState::Open { .. } = new_state { "opening IT-Syndikat - Ohai!" } else { @@ -159,7 +159,7 @@ impl Bot { } } - *self.open_state.lock().unwrap() = new_state; + *self.open_state.lock().unwrap() = Some(new_state); Ok(new_state) }