Massive config overhaul #6

Merged
Dreaded_X merged 23 commits from feature/improve_config into master 2025-10-22 02:17:46 +00:00
5 changed files with 34 additions and 2 deletions
Showing only changes of commit 84e8942fc9 - Show all commits

1
Cargo.lock generated
View File

@@ -99,6 +99,7 @@ dependencies = [
"git-version",
"google_home",
"inventory",
"lua_typed",
"mlua",
"reqwest",
"rumqttc",

View File

@@ -77,6 +77,7 @@ config = { version = "0.15.15", default-features = false, features = [
] }
git-version = "0.3.9"
google_home = { workspace = true }
lua_typed = { workspace = true }
inventory = { workspace = true }
mlua = { workspace = true }
reqwest = { workspace = true }

12
definitions/config.lua Normal file
View File

@@ -0,0 +1,12 @@
-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED
---@meta
---@class FulfillmentConfig
---@field openid_url string
---@field ip string?
---@field port integer?
local FulfillmentConfig
---@class Config
---@field fulfillment FulfillmentConfig
local Config

View File

@@ -1,7 +1,9 @@
use std::fs::{self, File};
use std::io::Write;
use automation::config::{Config, FulfillmentConfig};
use automation_lib::Module;
use lua_typed::Typed;
use tracing::{info, warn};
extern crate automation_devices;
@@ -24,6 +26,17 @@ fn write_definitions(filename: &str, definitions: &str) -> std::io::Result<()> {
Ok(())
}
fn config_definitions() -> String {
let mut output = "---@meta\n\n".to_string();
output +=
&FulfillmentConfig::generate_full().expect("FulfillmentConfig should have a definition");
output += "\n";
output += &Config::generate_full().expect("Config should have a definition");
output
}
fn main() -> std::io::Result<()> {
tracing_subscriber::fmt::init();
@@ -38,5 +51,7 @@ fn main() -> std::io::Result<()> {
}
}
write_definitions("config.lua", &config_definitions())?;
Ok(())
}

View File

@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::net::{Ipv4Addr, SocketAddr};
use lua_typed::Typed;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
@@ -17,16 +18,18 @@ fn default_entrypoint() -> String {
"./config.lua".into()
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Typed)]
pub struct FulfillmentConfig {
pub openid_url: String,
#[serde(default = "default_fulfillment_ip")]
#[typed(default)]
pub ip: Ipv4Addr,
#[serde(default = "default_fulfillment_port")]
#[typed(default)]
pub port: u16,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Typed)]
pub struct Config {
pub fulfillment: FulfillmentConfig,
}