Add relay pulse functionality

This commit is contained in:
Tobias Reisinger 2024-04-26 16:15:24 +02:00
parent e2f3d7b82a
commit 61a3c6093b
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
14 changed files with 201 additions and 13 deletions
emgauwa-lib/src/models

View file

@ -1,3 +1,5 @@
use std::time::Instant;
use actix::MessageResponse;
use chrono::NaiveTime;
use futures::executor::block_on;
@ -70,4 +72,15 @@ impl Controller {
.filter_map(|r| r.active_schedule.get_next_time(now))
.min()
}
pub fn relay_pulse(&mut self, relay_num: i64, until: Instant) -> Result<(), EmgauwaError> {
let relay = self
.relays
.iter_mut()
.find(|r| r.r.number == relay_num)
.ok_or(EmgauwaError::Other(String::from("Relay not found")))?;
relay.pulsing = Some(until);
Ok(())
}
}