From 1e2afe481c1272111c8d99cfbaf320298078fc64 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Wed, 29 May 2024 15:51:59 +0200 Subject: [PATCH] Remove guessing of active_schedule --- src/main.rs | 13 ++++++++----- src/relay_loop.rs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0c7eee0..0da73b5 100644 --- a/src/main.rs +++ b/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 = 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 = None; diff --git a/src/relay_loop.rs b/src/relay_loop.rs index d5f1676..366a3de 100644 --- a/src/relay_loop.rs +++ b/src/relay_loop.rs @@ -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(), ); });