feat: Receive devices through config return
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user