Don't require spaceapi to be available immediately on startup

Important because homeassistant is slow as hell
This commit is contained in:
Xiretza 2024-01-26 21:07:45 +00:00
parent ff505e98ae
commit c2b4ab9383

View file

@ -89,7 +89,7 @@ pub struct Bot {
client: Client,
api: ItsApi,
open_state: Mutex<OpenState>,
open_state: Mutex<Option<OpenState>>,
}
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<OpenState> {
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)
}