feat(config)!: Device creation function is now named entry

It now has to be called 'setup', this makes it possible to just
include the table as a whole in devices and it will automatically call
the correct function.
This commit is contained in:
2025-10-20 04:08:55 +02:00
parent 2056c6c70d
commit bc75f7005c
6 changed files with 41 additions and 27 deletions

View File

@@ -140,8 +140,8 @@ async fn app() -> anyhow::Result<()> {
let mqtt_client = mqtt::start(config.mqtt, &device_manager.event_channel());
if let Some(devices) = config.devices {
for device in devices.get(&lua, &mqtt_client).await? {
if let Some(modules) = config.modules {
for device in modules.setup(&lua, &mqtt_client).await? {
device_manager.add(device).await;
}
}

View File

@@ -1,7 +1,7 @@
use std::fs::{self, File};
use std::io::Write;
use automation::config::{Config, Devices, FulfillmentConfig};
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 += &Devices::generate_full().expect("Devices 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";