Add function to update reconnecting controllers
This commit is contained in:
parent
0b0350da0e
commit
ccc30dcdaf
1 changed files with 14 additions and 3 deletions
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue