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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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())?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user