use std::sync::Arc; use actix::Addr; use emgauwa_lib::errors::EmgauwaError; use emgauwa_lib::models::Controller; use emgauwa_lib::types::RelayStates; use tokio::sync::Notify; use crate::app_state; use crate::app_state::AppState; pub async fn app_state_get_this(app_state: &Addr<AppState>) -> Result<Controller, EmgauwaError> { app_state .send(app_state::GetThis {}) .await .map_err(EmgauwaError::from) } pub async fn app_state_get_relay_notifier( app_state: &Addr<AppState>, ) -> Result<Arc<Notify>, EmgauwaError> { app_state .send(app_state::GetRelayNotifier {}) .await .map_err(EmgauwaError::from) } pub async fn app_state_get_controller_notifier( app_state: &Addr<AppState>, ) -> Result<Arc<Notify>, EmgauwaError> { app_state .send(app_state::GetControllerNotifier {}) .await .map_err(EmgauwaError::from) } pub async fn app_state_reload(app_state: &Addr<AppState>) -> Result<(), EmgauwaError> { app_state .send(app_state::Reload {}) .await .map_err(EmgauwaError::from)? } pub async fn app_state_update_relays_on( app_state: &Addr<AppState>, relay_states: RelayStates, ) -> Result<(), EmgauwaError> { app_state .send(app_state::UpdateRelayStates { relay_states }) .await .map_err(EmgauwaError::from) }