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:
@@ -1,3 +1,4 @@
|
|||||||
|
local automation = require("automation")
|
||||||
print(_VERSION)
|
print(_VERSION)
|
||||||
|
|
||||||
local host = automation.util.get_hostname()
|
local host = automation.util.get_hostname()
|
||||||
@@ -16,7 +17,7 @@ local function mqtt_automation(topic)
|
|||||||
return "automation/" .. topic
|
return "automation/" .. topic
|
||||||
end
|
end
|
||||||
|
|
||||||
automation.fulfillment = {
|
local fulfillment = {
|
||||||
openid_url = "https://login.huizinga.dev/api/oidc",
|
openid_url = "https://login.huizinga.dev/api/oidc",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,3 +678,5 @@ end)
|
|||||||
automation.device_manager:schedule("0 0 20 * * *", function()
|
automation.device_manager:schedule("0 0 20 * * *", function()
|
||||||
bedroom_air_filter:set_on(false)
|
bedroom_air_filter:set_on(false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
return fulfillment
|
||||||
|
|||||||
21
src/main.rs
21
src/main.rs
@@ -6,7 +6,6 @@ use std::path::Path;
|
|||||||
use std::process;
|
use std::process;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use anyhow::anyhow;
|
|
||||||
use automation_lib::config::{FulfillmentConfig, MqttConfig};
|
use automation_lib::config::{FulfillmentConfig, MqttConfig};
|
||||||
use automation_lib::device_manager::DeviceManager;
|
use automation_lib::device_manager::DeviceManager;
|
||||||
use automation_lib::helpers;
|
use automation_lib::helpers;
|
||||||
@@ -77,7 +76,6 @@ async fn app() -> anyhow::Result<()> {
|
|||||||
// Setup the device handler
|
// Setup the device handler
|
||||||
let device_manager = DeviceManager::new().await;
|
let device_manager = DeviceManager::new().await;
|
||||||
|
|
||||||
let fulfillment_config = {
|
|
||||||
let lua = mlua::Lua::new();
|
let lua = mlua::Lua::new();
|
||||||
|
|
||||||
lua.set_warning_function(|_lua, text, _cont| {
|
lua.set_warning_function(|_lua, text, _cont| {
|
||||||
@@ -154,7 +152,7 @@ async fn app() -> anyhow::Result<()> {
|
|||||||
util.set("get_epoch", get_epoch)?;
|
util.set("get_epoch", get_epoch)?;
|
||||||
automation.set("util", util)?;
|
automation.set("util", util)?;
|
||||||
|
|
||||||
lua.globals().set("automation", automation)?;
|
lua.register_module("automation", automation)?;
|
||||||
|
|
||||||
automation_devices::register_with_lua(&lua)?;
|
automation_devices::register_with_lua(&lua)?;
|
||||||
helpers::register_with_lua(&lua)?;
|
helpers::register_with_lua(&lua)?;
|
||||||
@@ -162,24 +160,9 @@ async fn app() -> anyhow::Result<()> {
|
|||||||
// TODO: Make this not hardcoded
|
// TODO: Make this not hardcoded
|
||||||
let config_filename = std::env::var("AUTOMATION_CONFIG").unwrap_or("./config.lua".into());
|
let config_filename = std::env::var("AUTOMATION_CONFIG").unwrap_or("./config.lua".into());
|
||||||
let config_path = Path::new(&config_filename);
|
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: mlua::Value = lua.load(config_path).eval_async().await?;
|
||||||
let fulfillment_config: Option<mlua::Value> = automation.get("fulfillment")?;
|
|
||||||
if let Some(fulfillment_config) = fulfillment_config {
|
|
||||||
let fulfillment_config: FulfillmentConfig = lua.from_value(fulfillment_config)?;
|
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
|
// Create google home fulfillment route
|
||||||
let fulfillment = Router::new().route("/google_home", post(fulfillment));
|
let fulfillment = Router::new().route("/google_home", post(fulfillment));
|
||||||
|
|||||||
Reference in New Issue
Block a user