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())?;