Compare commits
4 Commits
14d51c0df6
...
d2d473c137
| Author | SHA1 | Date | |
|---|---|---|---|
|
d2d473c137
|
|||
|
a0ed373971
|
|||
|
5e13dff2b5
|
|||
|
ba818c6b60
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -99,6 +99,7 @@ dependencies = [
|
|||||||
"git-version",
|
"git-version",
|
||||||
"google_home",
|
"google_home",
|
||||||
"inventory",
|
"inventory",
|
||||||
|
"lua_typed",
|
||||||
"mlua",
|
"mlua",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rumqttc",
|
"rumqttc",
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ config = { version = "0.15.15", default-features = false, features = [
|
|||||||
] }
|
] }
|
||||||
git-version = "0.3.9"
|
git-version = "0.3.9"
|
||||||
google_home = { workspace = true }
|
google_home = { workspace = true }
|
||||||
|
lua_typed = { workspace = true }
|
||||||
inventory = { workspace = true }
|
inventory = { workspace = true }
|
||||||
mlua = { workspace = true }
|
mlua = { workspace = true }
|
||||||
reqwest = { workspace = true }
|
reqwest = { workspace = true }
|
||||||
|
|||||||
@@ -744,6 +744,7 @@ device_manager:schedule("0 0 20 * * *", function()
|
|||||||
bedroom_air_filter:set_on(false)
|
bedroom_air_filter:set_on(false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
---@type Config
|
||||||
return {
|
return {
|
||||||
fulfillment = {
|
fulfillment = {
|
||||||
openid_url = "https://login.huizinga.dev/api/oidc",
|
openid_url = "https://login.huizinga.dev/api/oidc",
|
||||||
|
|||||||
12
definitions/config.lua
Normal file
12
definitions/config.lua
Normal 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
|
||||||
@@ -1,32 +1,57 @@
|
|||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
|
use automation::config::{Config, FulfillmentConfig};
|
||||||
use automation_lib::Module;
|
use automation_lib::Module;
|
||||||
|
use lua_typed::Typed;
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
extern crate automation_devices;
|
extern crate automation_devices;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn write_definitions(filename: &str, definitions: &str) -> std::io::Result<()> {
|
||||||
tracing_subscriber::fmt::init();
|
|
||||||
|
|
||||||
let definitions_directory =
|
let definitions_directory =
|
||||||
std::path::Path::new(std::env!("CARGO_MANIFEST_DIR")).join("definitions");
|
std::path::Path::new(std::env!("CARGO_MANIFEST_DIR")).join("definitions");
|
||||||
fs::create_dir_all(&definitions_directory)?;
|
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> {
|
for module in inventory::iter::<Module> {
|
||||||
if let Some(definitions) = module.definitions() {
|
if let Some(definitions) = module.definitions() {
|
||||||
info!(name = module.get_name(), "Generating definitions");
|
info!(name = module.get_name(), "Generating definitions");
|
||||||
|
|
||||||
let filename = format!("{}.lua", module.get_name());
|
let filename = format!("{}.lua", module.get_name());
|
||||||
let mut file = File::create(definitions_directory.join(filename))?;
|
write_definitions(&filename, &definitions)?;
|
||||||
|
|
||||||
file.write_all(b"-- DO NOT MODIFY, FILE IS AUTOMATICALLY GENERATED\n")?;
|
|
||||||
file.write_all(definitions.as_bytes())?;
|
|
||||||
file.write_all(b"\n")?;
|
|
||||||
} else {
|
} else {
|
||||||
warn!(name = module.get_name(), "No definitions");
|
warn!(name = module.get_name(), "No definitions");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write_definitions("config.lua", &config_definitions())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::{Ipv4Addr, SocketAddr};
|
use std::net::{Ipv4Addr, SocketAddr};
|
||||||
|
|
||||||
|
use lua_typed::Typed;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
@@ -17,16 +18,18 @@ fn default_entrypoint() -> String {
|
|||||||
"./config.lua".into()
|
"./config.lua".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Typed)]
|
||||||
pub struct FulfillmentConfig {
|
pub struct FulfillmentConfig {
|
||||||
pub openid_url: String,
|
pub openid_url: String,
|
||||||
#[serde(default = "default_fulfillment_ip")]
|
#[serde(default = "default_fulfillment_ip")]
|
||||||
|
#[typed(default)]
|
||||||
pub ip: Ipv4Addr,
|
pub ip: Ipv4Addr,
|
||||||
#[serde(default = "default_fulfillment_port")]
|
#[serde(default = "default_fulfillment_port")]
|
||||||
|
#[typed(default)]
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize, Typed)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub fulfillment: FulfillmentConfig,
|
pub fulfillment: FulfillmentConfig,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user