Added lua function to get the current hostname
This makes it possible to set options depending on what machine we are running
This commit is contained in:
parent
631fac5061
commit
d085e536ca
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -85,6 +85,7 @@ dependencies = [
|
||||||
"eui48",
|
"eui48",
|
||||||
"futures",
|
"futures",
|
||||||
"google-home",
|
"google-home",
|
||||||
|
"hostname",
|
||||||
"impl_cast",
|
"impl_cast",
|
||||||
"indexmap 2.0.0",
|
"indexmap 2.0.0",
|
||||||
"mlua",
|
"mlua",
|
||||||
|
@ -689,6 +690,17 @@ dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hostname"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9c7c7c8ac16c798734b8a24560c1362120597c40d5e1459f09498f8f6c8f2ba"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"windows 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "0.2.9"
|
version = "0.2.9"
|
||||||
|
@ -790,7 +802,7 @@ dependencies = [
|
||||||
"iana-time-zone-haiku",
|
"iana-time-zone-haiku",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"windows",
|
"windows 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2304,6 +2316,25 @@ dependencies = [
|
||||||
"windows-targets 0.48.1",
|
"windows-targets 0.48.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
|
||||||
|
dependencies = [
|
||||||
|
"windows-core",
|
||||||
|
"windows-targets 0.52.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-core"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.48.0"
|
version = "0.48.0"
|
||||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -42,8 +42,16 @@ enum_dispatch = "0.3.12"
|
||||||
indexmap = { version = "2.0.0", features = ["serde"] }
|
indexmap = { version = "2.0.0", features = ["serde"] }
|
||||||
serde_yaml = "0.9.27"
|
serde_yaml = "0.9.27"
|
||||||
tokio-cron-scheduler = "0.9.4"
|
tokio-cron-scheduler = "0.9.4"
|
||||||
mlua = { version = "0.9.7", features = ["lua54", "vendored", "macros", "serialize", "async", "send"] }
|
mlua = { version = "0.9.7", features = [
|
||||||
|
"lua54",
|
||||||
|
"vendored",
|
||||||
|
"macros",
|
||||||
|
"serialize",
|
||||||
|
"async",
|
||||||
|
"send",
|
||||||
|
] }
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
|
hostname = "0.4.0"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
wakey = { git = "https://git.huizinga.dev/Dreaded_X/wakey" }
|
wakey = { git = "https://git.huizinga.dev/Dreaded_X/wakey" }
|
||||||
|
|
17
config.lua
17
config.lua
|
@ -1,8 +1,7 @@
|
||||||
print("Hello from lua")
|
print("Hello from lua")
|
||||||
|
|
||||||
automation.fulfillment = {
|
local host = automation.util.get_hostname()
|
||||||
openid_url = "https://login.huizinga.dev/api/oidc",
|
print("Running @" .. host)
|
||||||
}
|
|
||||||
|
|
||||||
local debug, value = pcall(automation.util.get_env, "DEBUG")
|
local debug, value = pcall(automation.util.get_env, "DEBUG")
|
||||||
if debug and value ~= "true" then
|
if debug and value ~= "true" then
|
||||||
|
@ -17,13 +16,19 @@ local function mqtt_automation(topic)
|
||||||
return "automation/" .. topic
|
return "automation/" .. topic
|
||||||
end
|
end
|
||||||
|
|
||||||
|
automation.fulfillment = {
|
||||||
|
openid_url = "https://login.huizinga.dev/api/oidc",
|
||||||
|
}
|
||||||
|
|
||||||
local mqtt_client = automation.new_mqtt_client({
|
local mqtt_client = automation.new_mqtt_client({
|
||||||
host = debug and "olympus.lan.huizinga.dev" or "mosquitto",
|
host = (host == "zeus" and "olympus.lan.huizinga.dev")
|
||||||
|
or (host == "hephaestus" and "olympus.vpn.huizinga.dev")
|
||||||
|
or "mosquitto",
|
||||||
port = 8883,
|
port = 8883,
|
||||||
client_name = debug and "automation-debug" or "automation_rs",
|
client_name = "automation-" .. host,
|
||||||
username = "mqtt",
|
username = "mqtt",
|
||||||
password = automation.util.get_env("MQTT_PASSWORD"),
|
password = automation.util.get_env("MQTT_PASSWORD"),
|
||||||
tls = debug and true or false,
|
tls = host == "zeus" or host == "hephaestus",
|
||||||
})
|
})
|
||||||
|
|
||||||
automation.device_manager:add(Ntfy.new({
|
automation.device_manager:add(Ntfy.new({
|
||||||
|
|
|
@ -84,6 +84,12 @@ async fn app() -> anyhow::Result<()> {
|
||||||
std::env::var(name).map_err(mlua::ExternalError::into_lua_err)
|
std::env::var(name).map_err(mlua::ExternalError::into_lua_err)
|
||||||
})?;
|
})?;
|
||||||
util.set("get_env", get_env)?;
|
util.set("get_env", get_env)?;
|
||||||
|
let get_hostname = lua.create_function(|_lua, ()| {
|
||||||
|
hostname::get()
|
||||||
|
.map(|name| name.to_str().unwrap_or("unknown").to_owned())
|
||||||
|
.map_err(mlua::ExternalError::into_lua_err)
|
||||||
|
})?;
|
||||||
|
util.set("get_hostname", get_hostname)?;
|
||||||
automation.set("util", util)?;
|
automation.set("util", util)?;
|
||||||
|
|
||||||
lua.globals().set("automation", automation)?;
|
lua.globals().set("automation", automation)?;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user