Add function to update reconnecting controllers

This commit is contained in:
Tobias Reisinger 2024-04-26 01:46:55 +02:00
parent 0b0350da0e
commit ccc30dcdaf
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE

View file

@ -2,13 +2,13 @@ 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 emgauwa_lib::types::{ControllerUid, ControllerWsAction, RelayStates};
use emgauwa_lib::utils;
use futures::executor::block_on;
use sqlx::pool::PoolConnection;
use sqlx::Sqlite;
use crate::app_state::{ConnectController, UpdateRelayStates};
use crate::app_state::{Action, ConnectController, UpdateRelayStates};
use crate::handlers::v1::ws::controllers::ControllersWs;
impl ControllersWs {
@ -31,6 +31,8 @@ impl ControllersWs {
c.relay_count,
))?;
block_on(controller_db.update_active(conn, true))?;
// update only the relay count
block_on(controller_db.update(conn, &controller_db.name, c.relay_count))?;
for relay in &controller.relays {
log::debug!(
@ -77,7 +79,16 @@ impl ControllersWs {
self.controller_uid = Some(controller_uid.clone());
block_on(self.app_state.send(ConnectController {
address: addr.recipient(),
controller,
controller: controller.clone(),
}))??;
block_on(self.app_state.send(Action {
controller_uid: controller_uid.clone(),
action: ControllerWsAction::Controller(controller.clone()),
}))??;
block_on(self.app_state.send(Action {
controller_uid: controller_uid.clone(),
action: ControllerWsAction::Relays(controller.relays),
}))??;
log::debug!("Done registering controller");