Add handler for relay states

This commit is contained in:
Tobias Reisinger 2024-04-25 14:10:32 +02:00
parent 82f2d49dc6
commit 55617dbd7c
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
8 changed files with 53 additions and 20 deletions
emgauwa-core/src/handlers/v1/ws/controllers

View file

@ -1,7 +1,10 @@
use std::hash::{Hash, Hasher};
use actix::{Actor, AsyncContext};
use emgauwa_lib::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule};
use emgauwa_lib::errors::{DatabaseError, EmgauwaError};
use emgauwa_lib::models::{Controller, FromDbModel};
use emgauwa_lib::types::{ControllerUid, RelayStates};
use futures::executor::block_on;
use sqlx::pool::PoolConnection;
use sqlx::Sqlite;
@ -81,4 +84,18 @@ impl ControllerWs {
log::debug!("Done registering controller");
Ok(())
}
pub fn handle_relay_states(
&mut self,
ctx: &mut <ControllerWs as Actor>::Context,
controller_uid: ControllerUid,
relay_states: RelayStates,
) -> Result<(), EmgauwaError> {
log::debug!(
"Received relay states: {:?} for {}",
relay_states,
controller_uid
);
Ok(())
}
}

View file

@ -54,6 +54,9 @@ impl ControllerWs {
) {
let action_res = match action {
ControllerWsAction::Register(controller) => self.handle_register(conn, ctx, controller),
ControllerWsAction::RelayStates((controller_uid, relay_states)) => {
self.handle_relay_states(ctx, controller_uid, relay_states)
}
_ => Ok(()),
};
if let Err(e) = action_res {