Split project (keep controller)
Some checks failed
/ build-artifacts (arm-unknown-linux-gnueabihf) (push) Failing after 9m37s

This commit is contained in:
Tobias Reisinger 2024-04-30 10:38:13 +02:00
parent 9bc75b9627
commit f4fbc95500
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
128 changed files with 37 additions and 7185 deletions

66
src/utils.rs Normal file
View file

@ -0,0 +1,66 @@
use std::sync::Arc;
use actix::Addr;
use emgauwa_common::errors::EmgauwaError;
use emgauwa_common::models::Controller;
use emgauwa_common::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)
}
pub async fn app_state_relay_pulse(
app_state: &Addr<AppState>,
relay_number: i64,
duration: Option<u32>,
) -> Result<(), EmgauwaError> {
app_state
.send(app_state::RelayPulse {
relay_number,
duration,
})
.await
.map_err(EmgauwaError::from)?
}