Refactor the utils (remove them)

This commit is contained in:
Tobias Reisinger 2024-05-29 00:59:08 +02:00
parent bb982c4444
commit b065c8dd97
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
6 changed files with 53 additions and 110 deletions

View file

@ -10,10 +10,9 @@ use emgauwa_common::utils::printable_relay_states;
use futures::pin_mut;
use tokio::time;
use tokio::time::timeout;
use utils::app_state_get_controller_notifier;
use crate::app_state::AppState;
use crate::utils;
use crate::app_state;
pub async fn run_relays_loop(app_state: Addr<AppState>) {
log::debug!("Spawned relays loop");
@ -27,10 +26,12 @@ pub async fn run_relays_loop(app_state: Addr<AppState>) {
}
async fn run_relays(app_state: &Addr<AppState>) -> Result<(), EmgauwaError> {
let notifier = &*app_state_get_controller_notifier(app_state).await?;
let notifier = &*app_state
.send(app_state::GetControllerNotifier {})
.await?;
let mut last_weekday = emgauwa_common::utils::get_weekday();
let mut this = utils::app_state_get_this(app_state).await?;
let mut this = AppState::get_this(app_state).await?;
let mut duration_override = None;
@ -52,7 +53,7 @@ async fn run_relays(app_state: &Addr<AppState>) -> Result<(), EmgauwaError> {
if changed {
log::debug!("Reloading controller in relay loop");
this = utils::app_state_get_this(app_state).await?;
this = AppState::get_this(app_state).await?;
}
log::debug!(
@ -97,8 +98,13 @@ async fn calc_relay_states(
|| relay.check_pulsing(&now.instant).is_some(),
);
});
let relay_states = this.get_relay_states();
utils::app_state_update_relay_states(app_state, relay_states.clone()).await
app_state
.send(app_state::UpdateRelayStates {
relay_states: this.get_relay_states()
})
.await
.map_err(EmgauwaError::from)
}
fn get_next_duration(
@ -136,7 +142,7 @@ async fn check_weekday(
if current_weekday.ne(last_weekday) {
log::debug!("Weekday changed");
*last_weekday = current_weekday;
utils::app_state_reload(app_state).await?;
AppState::trigger_reload(app_state).await?;
*changed = true;
}