From ba37de39396f4c499fc6157ff1f6243758fe3a87 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Thu, 4 Sep 2025 04:06:20 +0200 Subject: [PATCH] feat(config)!: Move new_mqtt_client out of global automation table into separate module The function `new_mqtt_client` was the last remaining entry in the global `automation` table. The function was renamed to `new` and placed in the new `mqtt` module. As `automation` is now empty, it has been removed. --- config.lua | 2 +- src/main.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/config.lua b/config.lua index 3738292..c12bf8f 100644 --- a/config.lua +++ b/config.lua @@ -23,7 +23,7 @@ local fulfillment = { openid_url = "https://login.huizinga.dev/api/oidc", } -local mqtt_client = automation.new_mqtt_client({ +local mqtt_client = require("mqtt").new({ host = ((host == "zeus" or host == "hephaestus") and "olympus.lan.huizinga.dev") or "mosquitto", port = 8883, client_name = "automation-" .. host, diff --git a/src/main.rs b/src/main.rs index 4c4cb0d..0fb6f1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -116,9 +116,9 @@ async fn app() -> anyhow::Result<()> { })?; lua.globals().set("print", print)?; - let automation = lua.create_table()?; + let mqtt = lua.create_table()?; let event_channel = device_manager.event_channel(); - let new_mqtt_client = lua.create_function(move |lua, config: mlua::Value| { + let mqtt_new = lua.create_function(move |lua, config: mlua::Value| { let config: MqttConfig = lua.from_value(config)?; // Create a mqtt client @@ -128,9 +128,8 @@ async fn app() -> anyhow::Result<()> { Ok(WrappedAsyncClient(client)) })?; - - automation.set("new_mqtt_client", new_mqtt_client)?; - lua.globals().set("automation", automation)?; + mqtt.set("new", mqtt_new)?; + lua.register_module("mqtt", mqtt)?; lua.register_module("device_manager", device_manager.clone())?;