Remove guessing of active_schedule

This commit is contained in:
Tobias Reisinger 2024-05-29 15:51:59 +02:00
parent b065c8dd97
commit 1e2afe481c
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 9 additions and 6 deletions

View file

@ -3,7 +3,7 @@ use emgauwa_common::db;
use emgauwa_common::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule}; use emgauwa_common::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule};
use emgauwa_common::errors::EmgauwaError; use emgauwa_common::errors::EmgauwaError;
use emgauwa_common::models::{Controller, FromDbModel}; 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 emgauwa_common::utils::{drop_privileges, init_logging};
use rppal_pfd::PiFaceDigital; use rppal_pfd::PiFaceDigital;
use sqlx::pool::PoolConnection; use sqlx::pool::PoolConnection;
@ -95,13 +95,16 @@ async fn main() -> Result<(), std::io::Error> {
.await .await
.map_err(EmgauwaError::from)?; .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 let initial_states: Vec<bool> = this
.relays .relays
.iter() .iter_mut()
.map(|r| r.active_schedule.is_on(&now)) .map(|r| {
r.reload_active_schedule(now.weekday);
r.is_on(&now.time)
})
.collect(); .collect();
let mut pfd: Option<PiFaceDigital> = None; let mut pfd: Option<PiFaceDigital> = None;

View file

@ -94,7 +94,7 @@ async fn calc_relay_states(
.for_each(|relay| { .for_each(|relay| {
relay.reload_active_schedule(now.weekday); relay.reload_active_schedule(now.weekday);
relay.is_on = Some( relay.is_on = Some(
relay.active_schedule.is_on(&now.time) relay.is_on(&now.time)
|| relay.check_pulsing(&now.instant).is_some(), || relay.check_pulsing(&now.instant).is_some(),
); );
}); });