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::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule};
 | 
				
			||||||
use emgauwa_lib::errors::{DatabaseError, EmgauwaError};
 | 
					use emgauwa_lib::errors::{DatabaseError, EmgauwaError};
 | 
				
			||||||
use emgauwa_lib::models::{Controller, FromDbModel};
 | 
					use emgauwa_lib::models::{Controller, FromDbModel};
 | 
				
			||||||
use emgauwa_lib::types::{ControllerUid, RelayStates};
 | 
					use emgauwa_lib::types::{ControllerUid, ControllerWsAction, RelayStates};
 | 
				
			||||||
use emgauwa_lib::utils;
 | 
					use emgauwa_lib::utils;
 | 
				
			||||||
use futures::executor::block_on;
 | 
					use futures::executor::block_on;
 | 
				
			||||||
use sqlx::pool::PoolConnection;
 | 
					use sqlx::pool::PoolConnection;
 | 
				
			||||||
use sqlx::Sqlite;
 | 
					use sqlx::Sqlite;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::app_state::{ConnectController, UpdateRelayStates};
 | 
					use crate::app_state::{Action, ConnectController, UpdateRelayStates};
 | 
				
			||||||
use crate::handlers::v1::ws::controllers::ControllersWs;
 | 
					use crate::handlers::v1::ws::controllers::ControllersWs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl ControllersWs {
 | 
					impl ControllersWs {
 | 
				
			||||||
| 
						 | 
					@ -31,6 +31,8 @@ impl ControllersWs {
 | 
				
			||||||
			c.relay_count,
 | 
								c.relay_count,
 | 
				
			||||||
		))?;
 | 
							))?;
 | 
				
			||||||
		block_on(controller_db.update_active(conn, true))?;
 | 
							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 {
 | 
							for relay in &controller.relays {
 | 
				
			||||||
			log::debug!(
 | 
								log::debug!(
 | 
				
			||||||
| 
						 | 
					@ -77,7 +79,16 @@ impl ControllersWs {
 | 
				
			||||||
		self.controller_uid = Some(controller_uid.clone());
 | 
							self.controller_uid = Some(controller_uid.clone());
 | 
				
			||||||
		block_on(self.app_state.send(ConnectController {
 | 
							block_on(self.app_state.send(ConnectController {
 | 
				
			||||||
			address: addr.recipient(),
 | 
								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");
 | 
							log::debug!("Done registering controller");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue