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
bb15558ab2
commit
bf3d757710
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -86,6 +86,7 @@ dependencies = [
|
|||
"eui48",
|
||||
"futures",
|
||||
"google-home",
|
||||
"hostname",
|
||||
"indexmap 2.0.0",
|
||||
"mlua",
|
||||
"once_cell",
|
||||
|
@ -693,6 +694,17 @@ dependencies = [
|
|||
"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]]
|
||||
name = "http"
|
||||
version = "0.2.9"
|
||||
|
@ -794,7 +806,7 @@ dependencies = [
|
|||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows",
|
||||
"windows 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2300,6 +2312,25 @@ dependencies = [
|
|||
"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]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -43,8 +43,16 @@ enum_dispatch = "0.3.12"
|
|||
indexmap = { version = "2.0.0", features = ["serde"] }
|
||||
serde_yaml = "0.9.27"
|
||||
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"
|
||||
hostname = "0.4.0"
|
||||
|
||||
[patch.crates-io]
|
||||
wakey = { git = "https://git.huizinga.dev/Dreaded_X/wakey" }
|
||||
|
|
17
config.lua
17
config.lua
|
@ -1,8 +1,7 @@
|
|||
print("Hello from lua")
|
||||
|
||||
automation.fulfillment = {
|
||||
openid_url = "https://login.huizinga.dev/api/oidc",
|
||||
}
|
||||
local host = automation.util.get_hostname()
|
||||
print("Running @" .. host)
|
||||
|
||||
local debug, value = pcall(automation.util.get_env, "DEBUG")
|
||||
if debug and value ~= "true" then
|
||||
|
@ -17,13 +16,19 @@ local function mqtt_automation(topic)
|
|||
return "automation/" .. topic
|
||||
end
|
||||
|
||||
automation.fulfillment = {
|
||||
openid_url = "https://login.huizinga.dev/api/oidc",
|
||||
}
|
||||
|
||||
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,
|
||||
client_name = debug and "automation-debug" or "automation_rs",
|
||||
client_name = "automation-" .. host,
|
||||
username = "mqtt",
|
||||
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({
|
||||
|
|
|
@ -84,6 +84,12 @@ async fn app() -> anyhow::Result<()> {
|
|||
std::env::var(name).map_err(mlua::ExternalError::into_lua_err)
|
||||
})?;
|
||||
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)?;
|
||||
|
||||
lua.globals().set("automation", automation)?;
|
||||
|
|
Loading…
Reference in New Issue
Block a user