Don't send opening message if only open_since changed
This happens with HomeAssistant reboots.
This commit is contained in:
parent
a339e71e6d
commit
c693b41a70
1 changed files with 13 additions and 4 deletions
17
src/bot.rs
17
src/bot.rs
|
@ -58,6 +58,12 @@ pub enum OpenState {
|
|||
Closed,
|
||||
}
|
||||
|
||||
impl OpenState {
|
||||
pub fn is_open(&self) -> bool {
|
||||
matches!(self, OpenState::Open { .. })
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(api))]
|
||||
async fn get_open_state(api: &ItsApi) -> Result<OpenState> {
|
||||
let state = api
|
||||
|
@ -146,13 +152,16 @@ impl Bot {
|
|||
#[instrument(skip(self))]
|
||||
async fn update_open_state(&self) -> Result<OpenState> {
|
||||
let new_state = get_open_state(&self.api).await?;
|
||||
if self
|
||||
|
||||
let is_open = new_state.is_open();
|
||||
let was_open = self
|
||||
.open_state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.is_some_and(|old_state| old_state != new_state)
|
||||
{
|
||||
let message = if let OpenState::Open { .. } = new_state {
|
||||
.as_ref()
|
||||
.map(OpenState::is_open);
|
||||
if was_open.is_some_and(|was_open| was_open != is_open) {
|
||||
let message = if is_open {
|
||||
"opening IT-Syndikat - Ohai!"
|
||||
} else {
|
||||
"closing IT-Syndikat - nap time!"
|
||||
|
|
Loading…
Reference in a new issue