Rename some stuff

This commit is contained in:
Tobias Reisinger 2026-08-31 21:34:23 +02:00
commit 49304c70bc
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
11 changed files with 183 additions and 23 deletions

2
.gitignore vendored
View file

@ -6,5 +6,5 @@
/emgauwa-*.sqlite
/emgauwa-*.sqlite-*
/emgauwa-*.json
/emgauwa-*.cfg.*

3
Cargo.lock generated
View file

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "actix"
@ -766,6 +766,7 @@ dependencies = [
"serde_with",
"simple_logger",
"sqlx",
"tokio",
"uuid",
]

View file

@ -5,7 +5,7 @@ edition = "2021"
authors = ["Tobias Reisinger <tobias@msrg.cc>"]
[dependencies]
emgauwa-common = { git = "https://git.serguzim.me/emgauwa/common.git" }
emgauwa-common = { git = "https://git.serguzim.me/emgauwa/common.git", tag = "v0.5.2-rc.1" }
actix = "0.13"

View file

@ -1,14 +1,14 @@
build-rpi:
cross build --target arm-unknown-linux-gnueabihf
emgauwa-controller.json: controller.pkl
emgauwa-controller.cfg.json: controller.pkl
pkl eval -f json -o $@ $<
config:
$(MAKE) emgauwa-controller.json
$(MAKE) emgauwa-controller.cfg.json
clean:
rm -f emgauwa-controller.json
rm -f emgauwa-controller.cfg.*
rm -f emgauwa-controller.sqlite
emgauwa-controller_%:

View file

@ -1,6 +1,10 @@
amends "package://emgauwa.app/pkl/emgauwa@0.2.1#/controller.pkl"
amends "package://emgauwa.app/pkl/emgauwa@0.2.3#/controller.pkl"
database = "sqlite://emgauwa-controller.sqlite"
server {
host = "127.0.0.1"
port = 4419
token = "dev token"
}

View file

@ -1,5 +1,5 @@
variable "REG" {
default = "registry.serguzim.me"
default = "rg.nl-ams.scw.cloud/public.serguzim.net"
}
variable "REPO" {
default = "emgauwa/controller"

75
emgauwa-controller.cfg Normal file
View file

@ -0,0 +1,75 @@
{
"server": {
"host": "127.0.0.1",
"port": 4419,
"token": "dev token"
},
"database": "sqlite://emgauwa-controller.sqlite",
"logging": {
"level": "DEBUG"
},
"relays": [
{
"number": 0,
"driver": "null",
"pin": 0,
"inverted": true
},
{
"number": 1,
"driver": "null",
"pin": 1,
"inverted": true
},
{
"number": 2,
"driver": "null",
"pin": 2,
"inverted": true
},
{
"number": 3,
"driver": "null",
"pin": 3,
"inverted": true
},
{
"number": 4,
"driver": "null",
"pin": 4,
"inverted": true
},
{
"number": 5,
"driver": "null",
"pin": 5,
"inverted": true
},
{
"number": 10,
"driver": "null",
"pin": 10,
"inverted": true,
"pulse": 10
},
{
"number": 11,
"driver": "null",
"pin": 11,
"inverted": true,
"pulse": 10
},
{
"number": 20,
"driver": "null",
"pin": 20,
"inverted": false
},
{
"number": 21,
"driver": "null",
"pin": 21,
"inverted": false
}
]
}

80
emgauwa-controller.json Normal file
View file

@ -0,0 +1,80 @@
{
"server": {
"host": "127.0.0.1",
"port": 4419,
"token": "dev token"
},
"database": "sqlite://emgauwa-controller.sqlite",
"permissions": {
"user": "",
"group": ""
},
"logging": {
"level": "DEBUG"
},
"midnight": "00:00",
"relays": [
{
"number": 0,
"driver": "null",
"pin": 0,
"inverted": true
},
{
"number": 1,
"driver": "null",
"pin": 1,
"inverted": true
},
{
"number": 2,
"driver": "null",
"pin": 2,
"inverted": true
},
{
"number": 3,
"driver": "null",
"pin": 3,
"inverted": true
},
{
"number": 4,
"driver": "null",
"pin": 4,
"inverted": true
},
{
"number": 5,
"driver": "null",
"pin": 5,
"inverted": true
},
{
"number": 10,
"driver": "null",
"pin": 10,
"inverted": true,
"pulse": 10
},
{
"number": 11,
"driver": "null",
"pin": 11,
"inverted": true,
"pulse": 10
},
{
"number": 20,
"driver": "null",
"pin": 20,
"inverted": false
},
{
"number": 21,
"driver": "null",
"pin": 21,
"inverted": false
}
]
}

View file

@ -64,8 +64,7 @@ async fn main() -> Result<(), std::io::Error> {
init_logging(&settings.logging)?;
let pool = db::init(&settings.database, 5)
.await
.map_err(EmgauwaError::from)?;
.await?;
let mut conn = pool.acquire().await.map_err(EmgauwaError::from)?;
@ -85,8 +84,7 @@ async fn main() -> Result<(), std::io::Error> {
.is_none()
{
create_this_relay(&mut conn, &db_controller, relay)
.await
.map_err(EmgauwaError::from)?;
.await?;
}
}
@ -97,6 +95,8 @@ async fn main() -> Result<(), std::io::Error> {
let mut this = Controller::from_db_model(&mut conn, db_controller).map_err(EmgauwaError::from)?;
conn.close().await.map_err(EmgauwaError::from)?;
let now = EmgauwaNow::now(&settings.midnight);
let initial_states: Vec<bool> = this
.relays

View file

@ -7,7 +7,7 @@ use tokio_tungstenite::tungstenite::Message;
use emgauwa_common::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule};
use emgauwa_common::errors::{DatabaseError, EmgauwaError};
use emgauwa_common::models::{Controller, Relay};
use emgauwa_common::types::{ControllerWsAction, ScheduleUid};
use emgauwa_common::types::{ControllersWsAction, ScheduleUid};
use crate::app_state::AppState;
use crate::app_state;
@ -48,19 +48,19 @@ pub async fn handle_message(
}
pub async fn handle_action(
conn: &mut PoolConnection<Sqlite>,
app_state: &Addr<AppState>,
action: ControllerWsAction,
conn: &mut PoolConnection<Sqlite>,
app_state: &Addr<AppState>,
action: ControllersWsAction,
) -> Result<(), EmgauwaError> {
let this = AppState::get_this(app_state).await?;
match action {
ControllerWsAction::Controller(controller) => {
ControllersWsAction::Controller(controller) => {
handle_controller(conn, &this, controller).await?
}
ControllerWsAction::Relays(relays) => handle_relays(conn, app_state, &this, relays).await?,
ControllerWsAction::Schedules(schedules) => handle_schedules(conn, schedules).await?,
ControllerWsAction::RelayPulse((relay_num, duration)) => {
ControllersWsAction::Relays(relays) => handle_relays(conn, app_state, &this, relays).await?,
ControllersWsAction::Schedules(schedules) => handle_schedules(conn, schedules).await?,
ControllersWsAction::RelayPulse((relay_num, duration)) => {
handle_relay_pulse(app_state, relay_num, duration).await?
}
_ => return Ok(()),

View file

@ -5,7 +5,7 @@ use actix::Addr;
use emgauwa_common::constants;
use emgauwa_common::constants::WEBSOCKET_RETRY_TIMEOUT;
use emgauwa_common::errors::EmgauwaError;
use emgauwa_common::types::ControllerWsAction;
use emgauwa_common::types::ControllersWsAction;
use futures::{future, pin_mut, SinkExt, StreamExt};
use sqlx::{Pool, Sqlite};
use tokio::time;
@ -67,7 +67,7 @@ async fn run_websocket(
let (mut write, read) = ws_stream.split();
let ws_action = ControllerWsAction::Register(AppState::get_this(app_state).await?);
let ws_action = ControllersWsAction::Register(AppState::get_this(app_state).await?);
let ws_action_json = serde_json::to_string(&ws_action)?;
if let Err(err) = write.send(Message::text(ws_action_json)).await {
@ -104,7 +104,7 @@ async fn read_app_state(
log::debug!("Relay change detected");
let this = AppState::get_this(&app_state).await?;
let relay_states = this.get_relay_states();
let ws_action = ControllerWsAction::RelayStates((this.c.uid, relay_states));
let ws_action = ControllersWsAction::RelayStates((this.c.uid, relay_states));
let ws_action_json = serde_json::to_string(&ws_action)?;
tx.unbounded_send(Message::text(ws_action_json))