Compare commits
2 Commits
915fb3f1a0
...
1101c600ab
| Author | SHA1 | Date | |
|---|---|---|---|
|
1101c600ab
|
|||
|
efa1f9aeee
|
@@ -21,6 +21,5 @@ RUN cargo auditable build --release
|
|||||||
|
|
||||||
FROM gcr.io/distroless/cc-debian12:nonroot AS runtime
|
FROM gcr.io/distroless/cc-debian12:nonroot AS runtime
|
||||||
COPY --from=builder /app/target/release/automation /app/automation
|
COPY --from=builder /app/target/release/automation /app/automation
|
||||||
ENV AUTOMATION__ENTRYPOINT=/app/config.lua
|
COPY ./config /app/config
|
||||||
COPY ./config.lua /app/config.lua
|
|
||||||
CMD [ "/app/automation" ]
|
CMD [ "/app/automation" ]
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ use std::collections::HashMap;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use lua_typed::Typed;
|
|
||||||
use mlua::FromLua;
|
|
||||||
use tokio::sync::{RwLock, RwLockReadGuard};
|
use tokio::sync::{RwLock, RwLockReadGuard};
|
||||||
use tracing::{debug, instrument, trace};
|
use tracing::{debug, instrument, trace};
|
||||||
|
|
||||||
@@ -12,7 +10,7 @@ use crate::event::{Event, EventChannel, OnMqtt};
|
|||||||
|
|
||||||
pub type DeviceMap = HashMap<String, Box<dyn Device>>;
|
pub type DeviceMap = HashMap<String, Box<dyn Device>>;
|
||||||
|
|
||||||
#[derive(Clone, FromLua)]
|
#[derive(Clone)]
|
||||||
pub struct DeviceManager {
|
pub struct DeviceManager {
|
||||||
devices: Arc<RwLock<DeviceMap>>,
|
devices: Arc<RwLock<DeviceMap>>,
|
||||||
event_channel: EventChannel,
|
event_channel: EventChannel,
|
||||||
@@ -89,21 +87,3 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl mlua::UserData for DeviceManager {
|
|
||||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
|
||||||
methods.add_async_method("add", async |_lua, this, device: Box<dyn Device>| {
|
|
||||||
this.add(device).await;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
|
|
||||||
methods.add_method("event_channel", |_lua, this, ()| Ok(this.event_channel()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Typed for DeviceManager {
|
|
||||||
fn type_name() -> String {
|
|
||||||
"DeviceManager".into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
---@meta
|
|
||||||
|
|
||||||
---@class DeviceManager
|
|
||||||
local DeviceManager
|
|
||||||
---@param device DeviceInterface
|
|
||||||
function DeviceManager:add(device) end
|
|
||||||
|
|
||||||
return DeviceManager
|
|
||||||
@@ -132,8 +132,6 @@ async fn app() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
automation_lib::load_modules(&lua)?;
|
automation_lib::load_modules(&lua)?;
|
||||||
|
|
||||||
lua.register_module("automation:device_manager", device_manager.clone())?;
|
|
||||||
|
|
||||||
lua.register_module("automation:variables", lua.to_value(&setup.variables)?)?;
|
lua.register_module("automation:variables", lua.to_value(&setup.variables)?)?;
|
||||||
lua.register_module("automation:secrets", lua.to_value(&setup.secrets)?)?;
|
lua.register_module("automation:secrets", lua.to_value(&setup.secrets)?)?;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub struct Setup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn default_entrypoint() -> String {
|
fn default_entrypoint() -> String {
|
||||||
"./config.lua".into()
|
"./config/config.lua".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Typed)]
|
#[derive(Debug, Deserialize, Typed)]
|
||||||
|
|||||||
Reference in New Issue
Block a user