Compare commits
2 Commits
40776ffe4c
...
8b4ea06957
| Author | SHA1 | Date | |
|---|---|---|---|
|
8b4ea06957
|
|||
|
be77711caf
|
@@ -1,4 +1,4 @@
|
||||
--- @type SetupInner
|
||||
--- @type SetupTable
|
||||
return {
|
||||
require("config.rooms.bathroom"),
|
||||
require("config.rooms.bedroom"),
|
||||
|
||||
@@ -9,14 +9,14 @@ local FulfillmentConfig
|
||||
|
||||
---@class Config
|
||||
---@field fulfillment FulfillmentConfig
|
||||
---@field modules Setup?
|
||||
---@field modules Modules?
|
||||
---@field mqtt MqttConfig
|
||||
---@field schedule table<string, fun() | fun()[]>?
|
||||
local Config
|
||||
|
||||
---@alias SetupFunction fun(mqtt_client: AsyncClient): SetupInner?
|
||||
---@alias SetupInner (DeviceInterface | { setup: SetupFunction } | SetupInner)[]
|
||||
---@alias Setup SetupFunction | SetupInner
|
||||
---@alias SetupFunction fun(mqtt_client: AsyncClient): SetupTable?
|
||||
---@alias SetupTable (DeviceInterface | { setup: SetupFunction? } | SetupTable)[]
|
||||
---@alias Modules SetupFunction | SetupTable
|
||||
|
||||
---@class MqttConfig
|
||||
---@field host string
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
|
||||
use automation::config::{Config, FulfillmentConfig, Setups};
|
||||
use automation::config::{Config, FulfillmentConfig, Modules};
|
||||
use automation_lib::Module;
|
||||
use automation_lib::mqtt::{MqttConfig, WrappedAsyncClient};
|
||||
use lua_typed::Typed;
|
||||
@@ -35,7 +35,7 @@ fn config_definitions() -> String {
|
||||
output += "\n";
|
||||
output += &Config::generate_full().expect("Config should have a definition");
|
||||
output += "\n";
|
||||
output += &Setups::generate_full().expect("Setups should have a definition");
|
||||
output += &Modules::generate_full().expect("Setups should have a definition");
|
||||
output += "\n";
|
||||
output += &MqttConfig::generate_full().expect("MqttConfig should have a definition");
|
||||
output += "\n";
|
||||
|
||||
@@ -35,9 +35,9 @@ pub struct FulfillmentConfig {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Setups(mlua::Value);
|
||||
pub struct Modules(mlua::Value);
|
||||
|
||||
impl Setups {
|
||||
impl Modules {
|
||||
pub async fn setup(
|
||||
self,
|
||||
lua: &mlua::Lua,
|
||||
@@ -84,15 +84,15 @@ impl Setups {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromLua for Setups {
|
||||
impl FromLua for Modules {
|
||||
fn from_lua(value: mlua::Value, _lua: &mlua::Lua) -> mlua::Result<Self> {
|
||||
Ok(Setups(value))
|
||||
Ok(Modules(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl Typed for Setups {
|
||||
impl Typed for Modules {
|
||||
fn type_name() -> String {
|
||||
"Setup".into()
|
||||
"Modules".into()
|
||||
}
|
||||
|
||||
fn generate_header() -> Option<String> {
|
||||
@@ -100,9 +100,9 @@ impl Typed for Setups {
|
||||
let client_type = WrappedAsyncClient::type_name();
|
||||
|
||||
Some(format!(
|
||||
r#"---@alias {type_name}Function fun(mqtt_client: {client_type}): {type_name}Inner?
|
||||
---@alias {type_name}Inner (DeviceInterface | {{ setup: {type_name}Function }} | {type_name}Inner)[]
|
||||
---@alias {type_name} {type_name}Function | {type_name}Inner
|
||||
r#"---@alias SetupFunction fun(mqtt_client: {client_type}): SetupTable?
|
||||
---@alias SetupTable (DeviceInterface | {{ setup: SetupFunction? }} | SetupTable)[]
|
||||
---@alias {type_name} SetupFunction | SetupTable
|
||||
"#,
|
||||
))
|
||||
}
|
||||
@@ -112,7 +112,7 @@ impl Typed for Setups {
|
||||
pub struct Config {
|
||||
pub fulfillment: FulfillmentConfig,
|
||||
#[device_config(from_lua, default)]
|
||||
pub modules: Option<Setups>,
|
||||
pub modules: Option<Modules>,
|
||||
#[device_config(from_lua)]
|
||||
pub mqtt: MqttConfig,
|
||||
#[device_config(from_lua, default)]
|
||||
|
||||
Reference in New Issue
Block a user