feat: Receive devices through config return

This commit is contained in:
2025-10-17 03:45:11 +02:00
parent 0c80cef5a1
commit 948380ea9b
7 changed files with 66 additions and 42 deletions

View File

@@ -136,8 +136,11 @@ async fn app() -> anyhow::Result<()> {
lua.register_module("automation:secrets", lua.to_value(&setup.secrets)?)?;
let entrypoint = Path::new(&setup.entrypoint);
let config: mlua::Value = lua.load(entrypoint).eval_async().await?;
let config: Config = lua.from_value(config)?;
let config: Config = lua.load(entrypoint).eval_async().await?;
for device in config.devices {
device_manager.add(device).await;
}
// Create google home fulfillment route
let fulfillment = Router::new().route("/google_home", post(fulfillment));

View File

@@ -1,6 +1,8 @@
use std::collections::HashMap;
use std::net::{Ipv4Addr, SocketAddr};
use automation_lib::device::Device;
use automation_macro::LuaDeviceConfig;
use lua_typed::Typed;
use serde::Deserialize;
@@ -29,9 +31,12 @@ pub struct FulfillmentConfig {
pub port: u16,
}
#[derive(Debug, Deserialize, Typed)]
#[derive(Debug, LuaDeviceConfig, Typed)]
pub struct Config {
pub fulfillment: FulfillmentConfig,
#[device_config(from_lua, default)]
#[typed(default)]
pub devices: Vec<Box<dyn Device>>,
}
impl From<FulfillmentConfig> for SocketAddr {