feat(config)!: Improve config module resolution
The new system is slightly less flexible, but the code and lua definitions is now a lot simpler and easier to understand. In fact the old lua definition was not actually correct. It is likely that existing configs require not/minimal tweaks to work again.
This commit is contained in:
@@ -140,10 +140,9 @@ async fn app() -> anyhow::Result<()> {
|
||||
|
||||
let mqtt_client = mqtt::start(config.mqtt, &device_manager.event_channel());
|
||||
|
||||
if let Some(modules) = config.modules {
|
||||
for device in modules.setup(&lua, &mqtt_client).await? {
|
||||
device_manager.add(device).await;
|
||||
}
|
||||
let resolved = config.modules.resolve(&lua, &mqtt_client).await?;
|
||||
for device in resolved.devices {
|
||||
device_manager.add(device).await;
|
||||
}
|
||||
|
||||
start_scheduler(config.schedule).await?;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
|
||||
use automation::config::{Config, FulfillmentConfig, Modules};
|
||||
use automation::config::{Config, FulfillmentConfig, Module as ConfigModule};
|
||||
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 += &Modules::generate_full().expect("Setups should have a definition");
|
||||
output += &ConfigModule::generate_full().expect("Module should have a definition");
|
||||
output += "\n";
|
||||
output += &MqttConfig::generate_full().expect("MqttConfig should have a definition");
|
||||
output += "\n";
|
||||
|
||||
Reference in New Issue
Block a user