Remove guessing of active_schedule
This commit is contained in:
parent
b065c8dd97
commit
1e2afe481c
2 changed files with 9 additions and 6 deletions
13
src/main.rs
13
src/main.rs
|
@ -3,7 +3,7 @@ use emgauwa_common::db;
|
|||
use emgauwa_common::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule};
|
||||
use emgauwa_common::errors::EmgauwaError;
|
||||
use emgauwa_common::models::{Controller, FromDbModel};
|
||||
use emgauwa_common::types::EmgauwaUid;
|
||||
use emgauwa_common::types::{EmgauwaNow, EmgauwaUid};
|
||||
use emgauwa_common::utils::{drop_privileges, init_logging};
|
||||
use rppal_pfd::PiFaceDigital;
|
||||
use sqlx::pool::PoolConnection;
|
||||
|
@ -95,13 +95,16 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
.await
|
||||
.map_err(EmgauwaError::from)?;
|
||||
|
||||
let this = Controller::from_db_model(&mut conn, db_controller).map_err(EmgauwaError::from)?;
|
||||
let mut this = Controller::from_db_model(&mut conn, db_controller).map_err(EmgauwaError::from)?;
|
||||
|
||||
let now = chrono::Local::now().time();
|
||||
let now = EmgauwaNow::now();
|
||||
let initial_states: Vec<bool> = this
|
||||
.relays
|
||||
.iter()
|
||||
.map(|r| r.active_schedule.is_on(&now))
|
||||
.iter_mut()
|
||||
.map(|r| {
|
||||
r.reload_active_schedule(now.weekday);
|
||||
r.is_on(&now.time)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut pfd: Option<PiFaceDigital> = None;
|
||||
|
|
|
@ -94,7 +94,7 @@ async fn calc_relay_states(
|
|||
.for_each(|relay| {
|
||||
relay.reload_active_schedule(now.weekday);
|
||||
relay.is_on = Some(
|
||||
relay.active_schedule.is_on(&now.time)
|
||||
relay.is_on(&now.time)
|
||||
|| relay.check_pulsing(&now.instant).is_some(),
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue