Compare commits

..

2 Commits

Author SHA1 Message Date
14d51c0df6 Move main.rs to bin/automation.rs
All checks were successful
Build and deploy / build (push) Successful in 11m12s
Build and deploy / Deploy container (push) Has been skipped
2025-10-17 02:57:18 +02:00
d5b28d5c6b Setup for expanding lua config return
All checks were successful
Build and deploy / build (push) Successful in 11m38s
Build and deploy / Deploy container (push) Has been skipped
Moves the application config out of automation_lib and sets up the
config return type for further expansion.
2025-10-17 02:41:08 +02:00
6 changed files with 10 additions and 53 deletions

1
Cargo.lock generated
View File

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

View File

@@ -77,7 +77,6 @@ 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 }

View File

@@ -744,7 +744,6 @@ device_manager:schedule("0 0 20 * * *", function()
bedroom_air_filter:set_on(false)
end)
---@type Config
return {
fulfillment = {
openid_url = "https://login.huizinga.dev/api/oidc",

View File

@@ -1,12 +0,0 @@
-- 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,57 +1,32 @@
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;
fn write_definitions(filename: &str, definitions: &str) -> std::io::Result<()> {
fn main() -> std::io::Result<()> {
tracing_subscriber::fmt::init();
let definitions_directory =
std::path::Path::new(std::env!("CARGO_MANIFEST_DIR")).join("definitions");
fs::create_dir_all(&definitions_directory)?;
let mut file = File::create(definitions_directory.join(filename))?;
file.write_all(b"-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED\n")?;
file.write_all(definitions.as_bytes())?;
// Make sure we have a trailing new line
if !definitions.ends_with("\n") {
file.write_all(b"\n")?;
}
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("FulfillmentConfig should have a definition");
output
}
fn main() -> std::io::Result<()> {
tracing_subscriber::fmt::init();
for module in inventory::iter::<Module> {
if let Some(definitions) = module.definitions() {
info!(name = module.get_name(), "Generating definitions");
let filename = format!("{}.lua", module.get_name());
write_definitions(&filename, &definitions)?;
let mut file = File::create(definitions_directory.join(filename))?;
file.write_all(b"-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED\n")?;
file.write_all(definitions.as_bytes())?;
file.write_all(b"\n")?;
} else {
warn!(name = module.get_name(), "No definitions");
}
}
write_definitions("config.lua", &config_definitions())?;
Ok(())
}

View File

@@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::net::{Ipv4Addr, SocketAddr};
use lua_typed::Typed;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
@@ -18,18 +17,16 @@ fn default_entrypoint() -> String {
"./config.lua".into()
}
#[derive(Debug, Deserialize, Typed)]
#[derive(Debug, Deserialize)]
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, Typed)]
#[derive(Debug, Deserialize)]
pub struct Config {
pub fulfillment: FulfillmentConfig,
}