feat(config)!: Fulfillment config is now returned at the end of the config

Previously the fulfillment config was set by setting
`automation.fulfillment`, this will no longer work in the future when
the global automation gets split into modules.
This commit is contained in:
2025-09-04 03:42:32 +02:00
parent 0090a77dc1
commit e626caad8a
2 changed files with 77 additions and 91 deletions

View File

@@ -1,3 +1,4 @@
local automation = require("automation")
print(_VERSION)
local host = automation.util.get_hostname()
@@ -16,7 +17,7 @@ local function mqtt_automation(topic)
return "automation/" .. topic
end
automation.fulfillment = {
local fulfillment = {
openid_url = "https://login.huizinga.dev/api/oidc",
}
@@ -677,3 +678,5 @@ end)
automation.device_manager:schedule("0 0 20 * * *", function()
bedroom_air_filter:set_on(false)
end)
return fulfillment

View File

@@ -6,7 +6,6 @@ use std::path::Path;
use std::process;
use std::time::{SystemTime, UNIX_EPOCH};
use anyhow::anyhow;
use automation_lib::config::{FulfillmentConfig, MqttConfig};
use automation_lib::device_manager::DeviceManager;
use automation_lib::helpers;
@@ -77,7 +76,6 @@ async fn app() -> anyhow::Result<()> {
// Setup the device handler
let device_manager = DeviceManager::new().await;
let fulfillment_config = {
let lua = mlua::Lua::new();
lua.set_warning_function(|_lua, text, _cont| {
@@ -154,7 +152,7 @@ async fn app() -> anyhow::Result<()> {
util.set("get_epoch", get_epoch)?;
automation.set("util", util)?;
lua.globals().set("automation", automation)?;
lua.register_module("automation", automation)?;
automation_devices::register_with_lua(&lua)?;
helpers::register_with_lua(&lua)?;
@@ -162,24 +160,9 @@ async fn app() -> anyhow::Result<()> {
// TODO: Make this not hardcoded
let config_filename = std::env::var("AUTOMATION_CONFIG").unwrap_or("./config.lua".into());
let config_path = Path::new(&config_filename);
match lua.load(config_path).exec_async().await {
Err(error) => {
println!("{error}");
Err(error)
}
result => result,
}?;
let automation: mlua::Table = lua.globals().get("automation")?;
let fulfillment_config: Option<mlua::Value> = automation.get("fulfillment")?;
if let Some(fulfillment_config) = fulfillment_config {
let fulfillment_config: mlua::Value = lua.load(config_path).eval_async().await?;
let fulfillment_config: FulfillmentConfig = lua.from_value(fulfillment_config)?;
debug!("automation.fulfillment = {fulfillment_config:?}");
fulfillment_config
} else {
return Err(anyhow!("Fulfillment is not configured"));
}
};
// Create google home fulfillment route
let fulfillment = Router::new().route("/google_home", post(fulfillment));