Rename ControllerUid to a more general EmgauwaUid (for macros)
This commit is contained in:
parent
07d3322c5a
commit
51aa0d3c99
11 changed files with 55 additions and 57 deletions
emgauwa-core/src
|
@ -4,7 +4,7 @@ use actix::{Actor, Addr, Context, Handler, Message, Recipient};
|
|||
use emgauwa_lib::db::DbController;
|
||||
use emgauwa_lib::errors::EmgauwaError;
|
||||
use emgauwa_lib::models::{convert_db_list, Controller, Relay};
|
||||
use emgauwa_lib::types::{ControllerUid, ControllerWsAction, RelayStates};
|
||||
use emgauwa_lib::types::{ControllerWsAction, EmgauwaUid, RelayStates};
|
||||
use futures::executor::block_on;
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
|
@ -13,7 +13,7 @@ use crate::handlers::v1::ws::relays::{RelaysWs, SendRelays};
|
|||
#[derive(Message)]
|
||||
#[rtype(result = "Result<(), EmgauwaError>")]
|
||||
pub struct DisconnectController {
|
||||
pub controller_uid: ControllerUid,
|
||||
pub controller_uid: EmgauwaUid,
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
|
@ -26,7 +26,7 @@ pub struct ConnectController {
|
|||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct UpdateRelayStates {
|
||||
pub controller_uid: ControllerUid,
|
||||
pub controller_uid: EmgauwaUid,
|
||||
pub relay_states: RelayStates,
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ pub struct GetRelays {}
|
|||
#[derive(Message)]
|
||||
#[rtype(result = "Result<(), EmgauwaError>")]
|
||||
pub struct Action {
|
||||
pub controller_uid: ControllerUid,
|
||||
pub controller_uid: EmgauwaUid,
|
||||
pub action: ControllerWsAction,
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ pub struct ConnectRelayClient {
|
|||
|
||||
pub struct AppState {
|
||||
pub pool: Pool<Sqlite>,
|
||||
pub connected_controllers: HashMap<ControllerUid, (Controller, Recipient<ControllerWsAction>)>,
|
||||
pub connected_controllers: HashMap<EmgauwaUid, (Controller, Recipient<ControllerWsAction>)>,
|
||||
pub connected_relay_clients: Vec<Addr<RelaysWs>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use actix_web::{delete, get, put, web, HttpResponse};
|
|||
use emgauwa_lib::db::DbController;
|
||||
use emgauwa_lib::errors::{DatabaseError, EmgauwaError};
|
||||
use emgauwa_lib::models::{convert_db_list, Controller, FromDbModel};
|
||||
use emgauwa_lib::types::{ControllerUid, ControllerWsAction, RequestControllerUpdate};
|
||||
use emgauwa_lib::types::{ControllerWsAction, EmgauwaUid, RequestControllerUpdate};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
use crate::app_state;
|
||||
|
@ -28,7 +28,7 @@ pub async fn show(
|
|||
let mut pool_conn = pool.acquire().await?;
|
||||
|
||||
let (controller_uid,) = path.into_inner();
|
||||
let uid = ControllerUid::try_from(controller_uid.as_str())?;
|
||||
let uid = EmgauwaUid::try_from(controller_uid.as_str())?;
|
||||
|
||||
let controller = DbController::get_by_uid(&mut pool_conn, &uid)
|
||||
.await?
|
||||
|
@ -40,15 +40,15 @@ pub async fn show(
|
|||
|
||||
#[put("/controllers/{controller_id}")]
|
||||
pub async fn update(
|
||||
pool: web::Data<Pool<Sqlite>>,
|
||||
app_state: web::Data<Addr<AppState>>,
|
||||
path: web::Path<(String,)>,
|
||||
data: web::Json<RequestControllerUpdate>,
|
||||
pool: web::Data<Pool<Sqlite>>,
|
||||
app_state: web::Data<Addr<AppState>>,
|
||||
path: web::Path<(String,)>,
|
||||
data: web::Json<RequestControllerUpdate>,
|
||||
) -> Result<HttpResponse, EmgauwaError> {
|
||||
let mut pool_conn = pool.acquire().await?;
|
||||
|
||||
let (controller_uid,) = path.into_inner();
|
||||
let uid = ControllerUid::try_from(controller_uid.as_str())?;
|
||||
let uid = EmgauwaUid::try_from(controller_uid.as_str())?;
|
||||
|
||||
let controller = DbController::get_by_uid(&mut pool_conn, &uid)
|
||||
.await?
|
||||
|
@ -79,7 +79,7 @@ pub async fn delete(
|
|||
let mut pool_conn = pool.acquire().await?;
|
||||
|
||||
let (controller_uid,) = path.into_inner();
|
||||
let uid = ControllerUid::try_from(controller_uid.as_str())?;
|
||||
let uid = EmgauwaUid::try_from(controller_uid.as_str())?;
|
||||
|
||||
app_state
|
||||
.send(app_state::DisconnectController {
|
||||
|
|
|
@ -3,9 +3,7 @@ use actix_web::{get, post, put, web, HttpResponse};
|
|||
use emgauwa_lib::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbTag};
|
||||
use emgauwa_lib::errors::{DatabaseError, EmgauwaError};
|
||||
use emgauwa_lib::models::{convert_db_list, FromDbModel, Relay};
|
||||
use emgauwa_lib::types::{
|
||||
ControllerUid, ControllerWsAction, RequestRelayPulse, RequestRelayUpdate,
|
||||
};
|
||||
use emgauwa_lib::types::{ControllerWsAction, EmgauwaUid, RequestRelayPulse, RequestRelayUpdate};
|
||||
use emgauwa_lib::utils;
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
|
@ -49,7 +47,7 @@ pub async fn index_for_controller(
|
|||
let mut pool_conn = pool.acquire().await?;
|
||||
|
||||
let (controller_uid,) = path.into_inner();
|
||||
let uid = ControllerUid::try_from(controller_uid.as_str())?;
|
||||
let uid = EmgauwaUid::try_from(controller_uid.as_str())?;
|
||||
|
||||
let controller = DbController::get_by_uid(&mut pool_conn, &uid)
|
||||
.await?
|
||||
|
@ -69,7 +67,7 @@ pub async fn show_for_controller(
|
|||
let mut pool_conn = pool.acquire().await?;
|
||||
|
||||
let (controller_uid, relay_num) = path.into_inner();
|
||||
let uid = ControllerUid::try_from(controller_uid.as_str())?;
|
||||
let uid = EmgauwaUid::try_from(controller_uid.as_str())?;
|
||||
|
||||
let controller = DbController::get_by_uid(&mut pool_conn, &uid)
|
||||
.await?
|
||||
|
@ -93,7 +91,7 @@ pub async fn update_for_controller(
|
|||
let mut pool_conn = pool.acquire().await?;
|
||||
|
||||
let (controller_uid, relay_num) = path.into_inner();
|
||||
let uid = ControllerUid::try_from(controller_uid.as_str())?;
|
||||
let uid = EmgauwaUid::try_from(controller_uid.as_str())?;
|
||||
|
||||
let controller = DbController::get_by_uid(&mut pool_conn, &uid)
|
||||
.await?
|
||||
|
@ -162,7 +160,7 @@ pub async fn pulse(
|
|||
let mut pool_conn = pool.acquire().await?;
|
||||
|
||||
let (controller_uid, relay_num) = path.into_inner();
|
||||
let uid = ControllerUid::try_from(controller_uid.as_str())?;
|
||||
let uid = EmgauwaUid::try_from(controller_uid.as_str())?;
|
||||
|
||||
let controller = DbController::get_by_uid(&mut pool_conn, &uid)
|
||||
.await?
|
||||
|
|
|
@ -2,7 +2,7 @@ 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, ControllerWsAction, RelayStates};
|
||||
use emgauwa_lib::types::{ControllerWsAction, EmgauwaUid, RelayStates};
|
||||
use emgauwa_lib::utils;
|
||||
use futures::executor::block_on;
|
||||
use sqlx::pool::PoolConnection;
|
||||
|
@ -97,7 +97,7 @@ impl ControllersWs {
|
|||
|
||||
pub fn handle_relay_states(
|
||||
&mut self,
|
||||
controller_uid: ControllerUid,
|
||||
controller_uid: EmgauwaUid,
|
||||
relay_states: RelayStates,
|
||||
) -> Result<(), EmgauwaError> {
|
||||
log::debug!(
|
||||
|
|
|
@ -7,7 +7,7 @@ use actix_web_actors::ws;
|
|||
use actix_web_actors::ws::ProtocolError;
|
||||
use emgauwa_lib::constants::{HEARTBEAT_INTERVAL, HEARTBEAT_TIMEOUT};
|
||||
use emgauwa_lib::errors::EmgauwaError;
|
||||
use emgauwa_lib::types::{ControllerUid, ControllerWsAction};
|
||||
use emgauwa_lib::types::{ControllerWsAction, EmgauwaUid};
|
||||
use futures::executor::block_on;
|
||||
use sqlx::pool::PoolConnection;
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
@ -18,7 +18,7 @@ use crate::utils::flatten_result;
|
|||
|
||||
pub struct ControllersWs {
|
||||
pub pool: Pool<Sqlite>,
|
||||
pub controller_uid: Option<ControllerUid>,
|
||||
pub controller_uid: Option<EmgauwaUid>,
|
||||
pub app_state: Addr<AppState>,
|
||||
pub hb: Instant,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue