Compare commits

...

10 Commits

Author SHA1 Message Date
c041c13dee Feat(config)!: Move new_mqtt_client out of global automation table into separate module
Some checks failed
Build and deploy / Deploy container (push) Blocked by required conditions
Build and deploy / build (push) Has been cancelled
The function `new_mqtt_client` was the last remaining entry in the
global `automation` table. The function was renamed to `new` and placed
in the new `mqtt` module. As `automation` is now empty, it has been
removed.
2025-09-04 04:06:20 +02:00
34095f53d6 Feat(config)!: Move device_manager out of global automation table into separate module
Moved `automation.device_manager` into a separate module called
`device_manager`
2025-09-04 04:01:38 +02:00
92ba41193d Feat(config)!: Move util out of global automation table into separate module
Move `automation.util` into a separate module called `utils`.
2025-09-04 03:59:32 +02:00
4db77a5a0a Feat(config)!: Fulfillment config is now returned at the end of the config
Previously the fulfillment config was set by setting
`automation.fulfillment`, this will no longer work in the future when
the global automation gets split into modules.
2025-09-04 03:46:45 +02:00
d71e907c2b Style: Sort crates by name
All checks were successful
Build and deploy / build (push) Successful in 10m30s
Build and deploy / Deploy container (push) Successful in 47s
2025-09-04 02:59:14 +02:00
4a120d4d35 Style: Enforce conventional commits formatting 2025-09-04 02:56:37 +02:00
7846649ea4 Chore: Put typos config in Cargo.toml 2025-09-04 02:56:37 +02:00
297ac9f1ee Chore: Update pre-commit hooks 2025-09-04 02:56:37 +02:00
926fdf84c4 Chore: Update/upgrade dependencies
There was a potential vulnerability in tracing-subscriber, so I took
this as an opportunity to update/upgrade all dependencies
2025-09-04 02:56:09 +02:00
d90eee8a75 Fix: Crash if hallway automation is called before door/trash have been initialized 2025-09-04 01:33:56 +02:00
12 changed files with 312 additions and 399 deletions

View File

@@ -1,6 +1,12 @@
default_install_hook_types:
- pre-commit
- commit-msg
default_stages:
- pre-commit
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 rev: v6.0.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: end-of-file-fixer - id: end-of-file-fixer
@@ -11,13 +17,20 @@ repos:
- id: check-added-large-files - id: check-added-large-files
- id: check-merge-conflict - id: check-merge-conflict
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.2.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
args: []
- repo: https://github.com/JohnnyMorganz/StyLua - repo: https://github.com/JohnnyMorganz/StyLua
rev: v0.20.0 rev: v2.1.0
hooks: hooks:
- id: stylua - id: stylua
- repo: https://github.com/crate-ci/typos - repo: https://github.com/crate-ci/typos
rev: v1.21.0 rev: v1.36.1
hooks: hooks:
- id: typos - id: typos
args: ["--force-exclude"] args: ["--force-exclude"]
@@ -75,6 +88,6 @@ repos:
pass_filenames: false pass_filenames: false
- repo: https://github.com/hadolint/hadolint - repo: https://github.com/hadolint/hadolint
rev: v2.12.0 rev: v2.13.1
hooks: hooks:
- id: hadolint - id: hadolint

View File

@@ -1,2 +0,0 @@
[default.extend-words]
mosquitto = "mosquitto"

246
Cargo.lock generated
View File

@@ -91,6 +91,7 @@ name = "automation"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait",
"automation_devices", "automation_devices",
"automation_lib", "automation_lib",
"axum", "axum",
@@ -121,7 +122,6 @@ dependencies = [
"async-trait", "async-trait",
"automation_lib", "automation_lib",
"automation_macro", "automation_macro",
"axum",
"bytes", "bytes",
"dyn-clone", "dyn-clone",
"eui48", "eui48",
@@ -172,13 +172,13 @@ dependencies = [
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.7.9" version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" checksum = "021e862c184ae977658b36c4500f7feac3221ca5da43e3f25bd04ab6c79a29b5"
dependencies = [ dependencies = [
"async-trait",
"axum-core", "axum-core",
"bytes", "bytes",
"form_urlencoded",
"futures-util", "futures-util",
"http", "http",
"http-body", "http-body",
@@ -206,13 +206,12 @@ dependencies = [
[[package]] [[package]]
name = "axum-core" name = "axum-core"
version = "0.4.5" version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6"
dependencies = [ dependencies = [
"async-trait",
"bytes", "bytes",
"futures-util", "futures-core",
"http", "http",
"http-body", "http-body",
"http-body-util", "http-body-util",
@@ -237,7 +236,7 @@ dependencies = [
"miniz_oxide", "miniz_oxide",
"object", "object",
"rustc-demangle", "rustc-demangle",
"windows-targets 0.52.6", "windows-targets",
] ]
[[package]] [[package]]
@@ -254,9 +253,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.9.3" version = "2.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
[[package]] [[package]]
name = "bme280" name = "bme280"
@@ -294,10 +293,11 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.34" version = "1.2.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" checksum = "590f9024a68a8c40351881787f1934dc11afd69090f5edb6831464694d836ea3"
dependencies = [ dependencies = [
"find-msvc-tools",
"shlex", "shlex",
] ]
@@ -466,7 +466,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.60.2", "windows-sys 0.52.0",
] ]
[[package]] [[package]]
@@ -479,6 +479,12 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "find-msvc-tools"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e178e4fba8a2726903f6ba98a6d221e76f9c12c650d5dc0e6afdc50677b49650"
[[package]] [[package]]
name = "flume" name = "flume"
version = "0.11.1" version = "0.11.1"
@@ -617,7 +623,7 @@ dependencies = [
"js-sys", "js-sys",
"libc", "libc",
"r-efi", "r-efi",
"wasi 0.14.2+wasi-0.2.4", "wasi 0.14.3+wasi-0.2.4",
"wasm-bindgen", "wasm-bindgen",
] ]
@@ -931,7 +937,7 @@ version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b"
dependencies = [ dependencies = [
"bitflags 2.9.3", "bitflags 2.9.4",
"cfg-if", "cfg-if",
"libc", "libc",
] ]
@@ -954,9 +960,9 @@ dependencies = [
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.13.0" version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
dependencies = [ dependencies = [
"either", "either",
] ]
@@ -1022,9 +1028,9 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.27" version = "0.4.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
[[package]] [[package]]
name = "lru-slab" name = "lru-slab"
@@ -1034,18 +1040,18 @@ checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
[[package]] [[package]]
name = "lua-src" name = "lua-src"
version = "547.0.0" version = "548.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1edaf29e3517b49b8b746701e5648ccb5785cde1c119062cbabbc5d5cd115e42" checksum = "00bc4bd1f1d5c65b30717333cbec4fa7aa378978940a1bca62f404498d423233"
dependencies = [ dependencies = [
"cc", "cc",
] ]
[[package]] [[package]]
name = "luajit-src" name = "luajit-src"
version = "210.5.12+a4f56a4" version = "210.6.1+f9140a6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a8e7962a5368d5f264d045a5a255e90f9aa3fc1941ae15a8d2940d42cac671" checksum = "813bd31f2759443affa687c0d9c5eb5cf6cb0e898810ab197408431d746054bf"
dependencies = [ dependencies = [
"cc", "cc",
"which", "which",
@@ -1077,9 +1083,9 @@ dependencies = [
[[package]] [[package]]
name = "matchit" name = "matchit"
version = "0.7.3" version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
[[package]] [[package]]
name = "maybe-async-cfg" name = "maybe-async-cfg"
@@ -1128,9 +1134,9 @@ dependencies = [
[[package]] [[package]]
name = "mlua" name = "mlua"
version = "0.10.5" version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1f5f8fbebc7db5f671671134b9321c4b9aa9adeafccfd9a8c020ae45c6a35d0" checksum = "5b3dd94c3c4dea0049b22296397040840a8f6b5b5229f438434ba82df402b42d"
dependencies = [ dependencies = [
"bstr", "bstr",
"either", "either",
@@ -1148,9 +1154,9 @@ dependencies = [
[[package]] [[package]]
name = "mlua-sys" name = "mlua-sys"
version = "0.6.8" version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "380c1f7e2099cafcf40e51d3a9f20a346977587aa4d012eae1f043149a728a93" checksum = "3d4dc9cfc5a7698899802e97480617d9726f7da78c910db989d4d0fd4991d900"
dependencies = [ dependencies = [
"cc", "cc",
"cfg-if", "cfg-if",
@@ -1161,9 +1167,9 @@ dependencies = [
[[package]] [[package]]
name = "mlua_derive" name = "mlua_derive"
version = "0.10.1" version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "870d71c172fcf491c6b5fb4c04160619a2ee3e5a42a1402269c66bcbf1dd4deb" checksum = "465bddde514c4eb3b50b543250e97c1d4b284fa3ef7dc0ba2992c77545dbceb2"
dependencies = [ dependencies = [
"itertools", "itertools",
"once_cell", "once_cell",
@@ -1176,12 +1182,11 @@ dependencies = [
[[package]] [[package]]
name = "nu-ansi-term" name = "nu-ansi-term"
version = "0.46.0" version = "0.50.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399"
dependencies = [ dependencies = [
"overload", "windows-sys 0.52.0",
"winapi",
] ]
[[package]] [[package]]
@@ -1234,12 +1239,6 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.4" version = "0.12.4"
@@ -1260,7 +1259,7 @@ dependencies = [
"libc", "libc",
"redox_syscall", "redox_syscall",
"smallvec", "smallvec",
"windows-targets 0.52.6", "windows-targets",
] ]
[[package]] [[package]]
@@ -1289,9 +1288,9 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
[[package]] [[package]]
name = "potential_utf" name = "potential_utf"
version = "0.1.2" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585" checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a"
dependencies = [ dependencies = [
"zerovec", "zerovec",
] ]
@@ -1353,7 +1352,7 @@ version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625" checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625"
dependencies = [ dependencies = [
"bitflags 2.9.3", "bitflags 2.9.4",
"memchr", "memchr",
"unicase", "unicase",
] ]
@@ -1410,7 +1409,7 @@ dependencies = [
"once_cell", "once_cell",
"socket2", "socket2",
"tracing", "tracing",
"windows-sys 0.60.2", "windows-sys 0.52.0",
] ]
[[package]] [[package]]
@@ -1463,7 +1462,7 @@ version = "0.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77"
dependencies = [ dependencies = [
"bitflags 2.9.3", "bitflags 2.9.4",
] ]
[[package]] [[package]]
@@ -1583,11 +1582,11 @@ version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"
dependencies = [ dependencies = [
"bitflags 2.9.3", "bitflags 2.9.4",
"errno", "errno",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
"windows-sys 0.60.2", "windows-sys 0.52.0",
] ]
[[package]] [[package]]
@@ -1705,7 +1704,7 @@ version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
dependencies = [ dependencies = [
"bitflags 2.9.3", "bitflags 2.9.4",
"core-foundation", "core-foundation",
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@@ -1991,9 +1990,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio-cron-scheduler" name = "tokio-cron-scheduler"
version = "0.13.0" version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a5597b569b4712cf78aa0c9ae29742461b7bda1e49c2a5fdad1d79bf022f8f0" checksum = "5c71ce8f810abc9fabebccc30302a952f9e89c6cf246fafaf170fef164063141"
dependencies = [ dependencies = [
"chrono", "chrono",
"croner", "croner",
@@ -2058,7 +2057,7 @@ version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"
dependencies = [ dependencies = [
"bitflags 2.9.3", "bitflags 2.9.4",
"bytes", "bytes",
"futures-util", "futures-util",
"http", "http",
@@ -2128,9 +2127,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.3.19" version = "0.3.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5"
dependencies = [ dependencies = [
"nu-ansi-term", "nu-ansi-term",
"sharded-slab", "sharded-slab",
@@ -2190,9 +2189,9 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.18.0" version = "1.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2"
dependencies = [ dependencies = [
"getrandom 0.3.3", "getrandom 0.3.3",
"js-sys", "js-sys",
@@ -2232,11 +2231,11 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.14.2+wasi-0.2.4" version = "0.14.3+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95"
dependencies = [ dependencies = [
"wit-bindgen-rt", "wit-bindgen",
] ]
[[package]] [[package]]
@@ -2351,28 +2350,6 @@ dependencies = [
"winsafe", "winsafe",
] ]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-core" name = "windows-core"
version = "0.61.2" version = "0.61.2"
@@ -2438,7 +2415,7 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [ dependencies = [
"windows-targets 0.52.6", "windows-targets",
] ]
[[package]] [[package]]
@@ -2447,16 +2424,7 @@ version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [ dependencies = [
"windows-targets 0.52.6", "windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
dependencies = [
"windows-targets 0.53.3",
] ]
[[package]] [[package]]
@@ -2465,31 +2433,14 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm 0.52.6", "windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.52.6", "windows_aarch64_msvc",
"windows_i686_gnu 0.52.6", "windows_i686_gnu",
"windows_i686_gnullvm 0.52.6", "windows_i686_gnullvm",
"windows_i686_msvc 0.52.6", "windows_i686_msvc",
"windows_x86_64_gnu 0.52.6", "windows_x86_64_gnu",
"windows_x86_64_gnullvm 0.52.6", "windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.52.6", "windows_x86_64_msvc",
]
[[package]]
name = "windows-targets"
version = "0.53.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
dependencies = [
"windows-link",
"windows_aarch64_gnullvm 0.53.0",
"windows_aarch64_msvc 0.53.0",
"windows_i686_gnu 0.53.0",
"windows_i686_gnullvm 0.53.0",
"windows_i686_msvc 0.53.0",
"windows_x86_64_gnu 0.53.0",
"windows_x86_64_gnullvm 0.53.0",
"windows_x86_64_msvc 0.53.0",
] ]
[[package]] [[package]]
@@ -2498,96 +2449,48 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_aarch64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
[[package]] [[package]]
name = "windows_i686_gnullvm" name = "windows_i686_gnullvm"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_i686_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "windows_x86_64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
[[package]] [[package]]
name = "winsafe" name = "winsafe"
version = "0.0.19" version = "0.0.19"
@@ -2595,13 +2498,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"
[[package]] [[package]]
name = "wit-bindgen-rt" name = "wit-bindgen"
version = "0.39.0" version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814"
dependencies = [
"bitflags 2.9.3",
]
[[package]] [[package]]
name = "writeable" name = "writeable"

View File

@@ -5,16 +5,38 @@ edition = "2024"
[workspace] [workspace]
members = [ members = [
"automation_macro",
"automation_cast", "automation_cast",
"google_home/google_home",
"google_home/google_home_macro",
"automation_devices", "automation_devices",
"automation_lib", "automation_lib",
"automation_macro",
"google_home/google_home",
"google_home/google_home_macro",
] ]
[workspace.dependencies] [workspace.dependencies]
mlua = { version = "0.10.1", features = [ air_filter_types = { git = "https://git.huizinga.dev/Dreaded_X/airfilter", tag = "v0.4.4" }
anyhow = "1.0.99"
async-trait = "0.1.89"
automation_cast = { path = "./automation_cast" }
automation_devices = { path = "./automation_devices" }
automation_lib = { path = "./automation_lib" }
automation_macro = { path = "./automation_macro" }
axum = "0.8.4"
bytes = "1.10.1"
dotenvy = "0.15.7"
dyn-clone = "1.0.20"
eui48 = { version = "1.1.0", features = [
"disp_hexstring",
"serde",
], default-features = false }
futures = "0.3.31"
google_home = { path = "./google_home/google_home" }
google_home_macro = { path = "./google_home/google_home_macro" }
hostname = "0.4.1"
indexmap = { version = "2.11.0", features = ["serde"] }
itertools = "0.14.0"
json_value_merge = "2.0.1"
mlua = { version = "0.11.3", features = [
"lua54", "lua54",
"vendored", "vendored",
"macros", "macros",
@@ -22,67 +44,49 @@ mlua = { version = "0.10.1", features = [
"async", "async",
"send", "send",
] } ] }
automation_macro = { path = "./automation_macro" } proc-macro2 = "1.0.101"
automation_cast = { path = "./automation_cast" } quote = "1.0.40"
automation_lib = { path = "./automation_lib" } reqwest = { version = "0.12.23", features = [
automation_devices = { path = "./automation_devices" }
google_home = { path = "./google_home/google_home" }
google_home_macro = { path = "./google_home/google_home_macro" }
tokio = { version = "1", features = ["rt-multi-thread"] }
rumqttc = "0.24.0"
tracing = "0.1.37"
anyhow = "1.0.68"
async-trait = "0.1.83"
axum = "0.7.9"
bytes = "1.3.0"
dotenvy = "0.15.0"
dyn-clone = "1.0.17"
eui48 = { version = "1.1.0", features = [
"disp_hexstring",
"serde",
], default-features = false }
futures = "0.3.25"
hostname = "0.4.0"
indexmap = { version = "2.0.0", features = ["serde"] }
itertools = "0.13.0"
json_value_merge = "2.0.0"
proc-macro2 = "1.0.81"
quote = "1.0.36"
reqwest = { version = "0.12.9", features = [
"json", "json",
"rustls-tls", "rustls-tls",
], default-features = false } # Use rustls, since the other packages also use rustls ], default-features = false } # Use rustls, since the other packages also use rustls
serde = { version = "1.0.149", features = ["derive"] } rumqttc = "0.24.0"
serde_json = "1.0.89" serde = { version = "1.0.219", features = ["derive"] }
serde_repr = "0.1.10" serde_json = "1.0.143"
syn = { version = "2.0.60", features = ["extra-traits", "full"] } serde_repr = "0.1.20"
thiserror = "2.0.5" syn = { version = "2.0.106", features = ["extra-traits", "full"] }
tokio-cron-scheduler = "0.13.0" thiserror = "2.0.16"
tracing-subscriber = "0.3.16" tokio = { version = "1", features = ["rt-multi-thread"] }
uuid = "1.8.0" tokio-cron-scheduler = "0.14.0"
tracing = "0.1.41"
tracing-subscriber = "0.3.20"
uuid = "1.18.1"
wakey = "0.3.0" wakey = "0.3.0"
air_filter_types = { git = "https://git.huizinga.dev/Dreaded_X/airfilter", tag = "v0.4.4" }
[dependencies] [dependencies]
automation_lib = { workspace = true }
automation_devices = { workspace = true }
google_home = { workspace = true }
mlua = { workspace = true }
tokio = { workspace = true }
hostname = { workspace = true }
rumqttc = { workspace = true }
axum = { workspace = true }
tracing = { workspace = true }
anyhow = { workspace = true } anyhow = { workspace = true }
async-trait = { workspace = true }
automation_devices = { workspace = true }
automation_lib = { workspace = true }
axum = { workspace = true }
dotenvy = { workspace = true } dotenvy = { workspace = true }
tracing-subscriber = { workspace = true } google_home = { workspace = true }
serde = { workspace = true } hostname = { workspace = true }
thiserror = { workspace = true } mlua = { workspace = true }
serde_json = { workspace = true }
reqwest = { workspace = true } reqwest = { workspace = true }
rumqttc = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
[patch.crates-io] [patch.crates-io]
wakey = { git = "https://git.huizinga.dev/Dreaded_X/wakey" } wakey = { git = "https://git.huizinga.dev/Dreaded_X/wakey" }
[profile.release] [profile.release]
lto = true lto = true
[package.metadata.typos.default.extend-words]
mosquitto = "mosquitto"

View File

@@ -3,6 +3,4 @@ name = "automation_cast"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]

View File

@@ -4,23 +4,22 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
air_filter_types = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
automation_lib = { workspace = true } automation_lib = { workspace = true }
automation_macro = { workspace = true } automation_macro = { workspace = true }
bytes = { workspace = true }
dyn-clone = { workspace = true }
eui48 = { workspace = true }
google_home = { workspace = true } google_home = { workspace = true }
mlua = { workspace = true } mlua = { workspace = true }
async-trait = { workspace = true } reqwest = { workspace = true }
dyn-clone = { workspace = true }
rumqttc = { workspace = true } rumqttc = { workspace = true }
tokio = { workspace = true }
serde_repr = { workspace = true }
tracing = { workspace = true }
serde_json = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
reqwest = { workspace = true } # Use rustls, since the other packages also use rustls serde_json = { workspace = true }
anyhow = { workspace = true } serde_repr = { workspace = true }
axum = { workspace = true }
bytes = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
eui48 = { workspace = true } tokio = { workspace = true }
tracing = { workspace = true }
wakey = { workspace = true } wakey = { workspace = true }
air_filter_types = { workspace = true }

View File

@@ -1,3 +1,4 @@
use async_trait::async_trait;
use automation_lib::action_callback::ActionCallback; use automation_lib::action_callback::ActionCallback;
use automation_lib::config::{InfoConfig, MqttDeviceConfig}; use automation_lib::config::{InfoConfig, MqttDeviceConfig};
use automation_lib::device::{Device, LuaDeviceCreate}; use automation_lib::device::{Device, LuaDeviceCreate};
@@ -5,7 +6,6 @@ use automation_lib::event::OnMqtt;
use automation_lib::messages::{RemoteAction, RemoteMessage}; use automation_lib::messages::{RemoteAction, RemoteMessage};
use automation_lib::mqtt::WrappedAsyncClient; use automation_lib::mqtt::WrappedAsyncClient;
use automation_macro::{LuaDevice, LuaDeviceConfig}; use automation_macro::{LuaDevice, LuaDeviceConfig};
use axum::async_trait;
use rumqttc::{Publish, matches}; use rumqttc::{Publish, matches};
use tracing::{debug, error, trace}; use tracing::{debug, error, trace};

View File

@@ -4,19 +4,19 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
async-trait = { workspace = true }
automation_cast = { workspace = true } automation_cast = { workspace = true }
bytes = { workspace = true }
dyn-clone = { workspace = true }
futures = { workspace = true }
google_home = { workspace = true } google_home = { workspace = true }
indexmap = { workspace = true }
mlua = { workspace = true }
rumqttc = { workspace = true } rumqttc = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
bytes = { workspace = true }
async-trait = { workspace = true }
futures = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
indexmap = { workspace = true } tokio = { workspace = true }
tokio-cron-scheduler = { workspace = true } tokio-cron-scheduler = { workspace = true }
mlua = { workspace = true } tracing = { workspace = true }
uuid = { workspace = true } uuid = { workspace = true }
dyn-clone = { workspace = true }

View File

@@ -1,9 +1,12 @@
local device_manager = require("device_manager")
local utils = require("utils")
print(_VERSION) print(_VERSION)
local host = automation.util.get_hostname() local host = utils.get_hostname()
print("Running @" .. host) print("Running @" .. host)
local debug, value = pcall(automation.util.get_env, "DEBUG") local debug, value = pcall(utils.get_env, "DEBUG")
if debug and value ~= "true" then if debug and value ~= "true" then
debug = false debug = false
end end
@@ -16,23 +19,23 @@ local function mqtt_automation(topic)
return "automation/" .. topic return "automation/" .. topic
end end
automation.fulfillment = { local fulfillment = {
openid_url = "https://login.huizinga.dev/api/oidc", openid_url = "https://login.huizinga.dev/api/oidc",
} }
local mqtt_client = automation.new_mqtt_client({ local mqtt_client = require("mqtt").new({
host = ((host == "zeus" or host == "hephaestus") and "olympus.lan.huizinga.dev") or "mosquitto", host = ((host == "zeus" or host == "hephaestus") and "olympus.lan.huizinga.dev") or "mosquitto",
port = 8883, port = 8883,
client_name = "automation-" .. host, client_name = "automation-" .. host,
username = "mqtt", username = "mqtt",
password = automation.util.get_env("MQTT_PASSWORD"), password = utils.get_env("MQTT_PASSWORD"),
tls = host == "zeus" or host == "hephaestus", tls = host == "zeus" or host == "hephaestus",
}) })
local ntfy = Ntfy.new({ local ntfy = Ntfy.new({
topic = automation.util.get_env("NTFY_TOPIC"), topic = utils.get_env("NTFY_TOPIC"),
}) })
automation.device_manager:add(ntfy) device_manager:add(ntfy)
local low_battery = {} local low_battery = {}
local function check_battery(device, battery) local function check_battery(device, battery)
@@ -44,7 +47,7 @@ local function check_battery(device, battery)
low_battery[id] = nil low_battery[id] = nil
end end
end end
automation.device_manager:schedule("0 0 21 */1 * *", function() device_manager:schedule("0 0 21 */1 * *", function()
-- Don't send notifications if there are now devices with low battery -- Don't send notifications if there are now devices with low battery
if next(low_battery) == nil then if next(low_battery) == nil then
print("No devices with low battery") print("No devices with low battery")
@@ -82,7 +85,7 @@ local presence_system = Presence.new({
end end
end, end,
}) })
automation.device_manager:add(presence_system) device_manager:add(presence_system)
on_presence:add(function(presence) on_presence:add(function(presence)
ntfy:send_notification({ ntfy:send_notification({
title = "Presence", title = "Presence",
@@ -105,7 +108,7 @@ end)
on_presence:add(function(presence) on_presence:add(function(presence)
mqtt_client:send_message(mqtt_automation("debug") .. "/presence", { mqtt_client:send_message(mqtt_automation("debug") .. "/presence", {
state = presence, state = presence,
updated = automation.util.get_epoch(), updated = utils.get_epoch(),
}) })
end) end)
@@ -122,7 +125,7 @@ local on_light = {
self[#self + 1] = f self[#self + 1] = f
end, end,
} }
automation.device_manager:add(LightSensor.new({ device_manager:add(LightSensor.new({
identifier = "living_light_sensor", identifier = "living_light_sensor",
topic = mqtt_z2m("living/light"), topic = mqtt_z2m("living/light"),
client = mqtt_client, client = mqtt_client,
@@ -139,12 +142,12 @@ automation.device_manager:add(LightSensor.new({
on_light:add(function(light) on_light:add(function(light)
mqtt_client:send_message(mqtt_automation("debug") .. "/darkness", { mqtt_client:send_message(mqtt_automation("debug") .. "/darkness", {
state = not light, state = not light,
updated = automation.util.get_epoch(), updated = utils.get_epoch(),
}) })
end) end)
local hue_ip = "10.0.0.102" local hue_ip = "10.0.0.102"
local hue_token = automation.util.get_env("HUE_TOKEN") local hue_token = utils.get_env("HUE_TOKEN")
local hue_bridge = HueBridge.new({ local hue_bridge = HueBridge.new({
identifier = "hue_bridge", identifier = "hue_bridge",
@@ -155,7 +158,7 @@ local hue_bridge = HueBridge.new({
darkness = 43, darkness = 43,
}, },
}) })
automation.device_manager:add(hue_bridge) device_manager:add(hue_bridge)
on_light:add(function(light) on_light:add(function(light)
hue_bridge:set_flag("darkness", not light) hue_bridge:set_flag("darkness", not light)
end) end)
@@ -170,7 +173,7 @@ local kitchen_lights = HueGroup.new({
group_id = 7, group_id = 7,
scene_id = "7MJLG27RzeRAEVJ", scene_id = "7MJLG27RzeRAEVJ",
}) })
automation.device_manager:add(kitchen_lights) device_manager:add(kitchen_lights)
local living_lights = HueGroup.new({ local living_lights = HueGroup.new({
identifier = "living_lights", identifier = "living_lights",
ip = hue_ip, ip = hue_ip,
@@ -178,7 +181,7 @@ local living_lights = HueGroup.new({
group_id = 1, group_id = 1,
scene_id = "SNZw7jUhQ3cXSjkj", scene_id = "SNZw7jUhQ3cXSjkj",
}) })
automation.device_manager:add(living_lights) device_manager:add(living_lights)
local living_lights_relax = HueGroup.new({ local living_lights_relax = HueGroup.new({
identifier = "living_lights", identifier = "living_lights",
ip = hue_ip, ip = hue_ip,
@@ -186,9 +189,9 @@ local living_lights_relax = HueGroup.new({
group_id = 1, group_id = 1,
scene_id = "eRJ3fvGHCcb6yNw", scene_id = "eRJ3fvGHCcb6yNw",
}) })
automation.device_manager:add(living_lights_relax) device_manager:add(living_lights_relax)
automation.device_manager:add(HueSwitch.new({ device_manager:add(HueSwitch.new({
name = "Switch", name = "Switch",
room = "Living", room = "Living",
client = mqtt_client, client = mqtt_client,
@@ -205,7 +208,7 @@ automation.device_manager:add(HueSwitch.new({
battery_callback = check_battery, battery_callback = check_battery,
})) }))
automation.device_manager:add(WakeOnLAN.new({ device_manager:add(WakeOnLAN.new({
name = "Zeus", name = "Zeus",
room = "Living Room", room = "Living Room",
topic = mqtt_automation("appliance/living_room/zeus"), topic = mqtt_automation("appliance/living_room/zeus"),
@@ -221,7 +224,7 @@ local living_mixer = OutletOnOff.new({
client = mqtt_client, client = mqtt_client,
}) })
turn_off_when_away(living_mixer) turn_off_when_away(living_mixer)
automation.device_manager:add(living_mixer) device_manager:add(living_mixer)
local living_speakers = OutletOnOff.new({ local living_speakers = OutletOnOff.new({
name = "Speakers", name = "Speakers",
room = "Living Room", room = "Living Room",
@@ -229,9 +232,9 @@ local living_speakers = OutletOnOff.new({
client = mqtt_client, client = mqtt_client,
}) })
turn_off_when_away(living_speakers) turn_off_when_away(living_speakers)
automation.device_manager:add(living_speakers) device_manager:add(living_speakers)
automation.device_manager:add(IkeaRemote.new({ device_manager:add(IkeaRemote.new({
name = "Remote", name = "Remote",
room = "Living Room", room = "Living Room",
client = mqtt_client, client = mqtt_client,
@@ -280,13 +283,13 @@ local kettle = OutletPower.new({
callback = kettle_timeout(), callback = kettle_timeout(),
}) })
turn_off_when_away(kettle) turn_off_when_away(kettle)
automation.device_manager:add(kettle) device_manager:add(kettle)
local function set_kettle(_, on) local function set_kettle(_, on)
kettle:set_on(on) kettle:set_on(on)
end end
automation.device_manager:add(IkeaRemote.new({ device_manager:add(IkeaRemote.new({
name = "Remote", name = "Remote",
room = "Bedroom", room = "Bedroom",
client = mqtt_client, client = mqtt_client,
@@ -296,7 +299,7 @@ automation.device_manager:add(IkeaRemote.new({
battery_callback = check_battery, battery_callback = check_battery,
})) }))
automation.device_manager:add(IkeaRemote.new({ device_manager:add(IkeaRemote.new({
name = "Remote", name = "Remote",
room = "Kitchen", room = "Kitchen",
client = mqtt_client, client = mqtt_client,
@@ -327,9 +330,9 @@ local bathroom_light = LightOnOff.new({
client = mqtt_client, client = mqtt_client,
callback = off_timeout(debug and 60 or 45 * 60), callback = off_timeout(debug and 60 or 45 * 60),
}) })
automation.device_manager:add(bathroom_light) device_manager:add(bathroom_light)
automation.device_manager:add(Washer.new({ device_manager:add(Washer.new({
identifier = "bathroom_washer", identifier = "bathroom_washer",
topic = mqtt_z2m("bathroom/washer"), topic = mqtt_z2m("bathroom/washer"),
client = mqtt_client, client = mqtt_client,
@@ -344,7 +347,7 @@ automation.device_manager:add(Washer.new({
end, end,
})) }))
automation.device_manager:add(OutletOnOff.new({ device_manager:add(OutletOnOff.new({
name = "Charger", name = "Charger",
room = "Workbench", room = "Workbench",
topic = mqtt_z2m("workbench/charger"), topic = mqtt_z2m("workbench/charger"),
@@ -359,7 +362,7 @@ local workbench_outlet = OutletOnOff.new({
client = mqtt_client, client = mqtt_client,
}) })
turn_off_when_away(workbench_outlet) turn_off_when_away(workbench_outlet)
automation.device_manager:add(workbench_outlet) device_manager:add(workbench_outlet)
local workbench_light = LightColorTemperature.new({ local workbench_light = LightColorTemperature.new({
name = "Light", name = "Light",
@@ -368,10 +371,10 @@ local workbench_light = LightColorTemperature.new({
client = mqtt_client, client = mqtt_client,
}) })
turn_off_when_away(workbench_light) turn_off_when_away(workbench_light)
automation.device_manager:add(workbench_light) device_manager:add(workbench_light)
local delay_color_temp = Timeout.new() local delay_color_temp = Timeout.new()
automation.device_manager:add(IkeaRemote.new({ device_manager:add(IkeaRemote.new({
name = "Remote", name = "Remote",
room = "Workbench", room = "Workbench",
client = mqtt_client, client = mqtt_client,
@@ -401,7 +404,7 @@ local hallway_top_light = HueGroup.new({
group_id = 83, group_id = 83,
scene_id = "QeufkFDICEHWeKJ7", scene_id = "QeufkFDICEHWeKJ7",
}) })
automation.device_manager:add(HueSwitch.new({ device_manager:add(HueSwitch.new({
name = "SwitchBottom", name = "SwitchBottom",
room = "Hallway", room = "Hallway",
client = mqtt_client, client = mqtt_client,
@@ -411,7 +414,7 @@ automation.device_manager:add(HueSwitch.new({
end, end,
battery_callback = check_battery, battery_callback = check_battery,
})) }))
automation.device_manager:add(HueSwitch.new({ device_manager:add(HueSwitch.new({
name = "SwitchTop", name = "SwitchTop",
room = "Hallway", room = "Hallway",
client = mqtt_client, client = mqtt_client,
@@ -437,7 +440,7 @@ local hallway_light_automation = {
self.group.set_on(true) self.group.set_on(true)
elseif not self.forced then elseif not self.forced then
self.timeout:start(debug and 10 or 2 * 60, function() self.timeout:start(debug and 10 or 2 * 60, function()
if self.trash:open_percent() == 0 then if self.trash == nil or self.trash:open_percent() == 0 then
self.group.set_on(false) self.group.set_on(false)
end end
end) end)
@@ -447,13 +450,21 @@ local hallway_light_automation = {
if open then if open then
self.group.set_on(true) self.group.set_on(true)
else else
if not self.timeout:is_waiting() and self.door:open_percent() == 0 and not self.forced then if
not self.timeout:is_waiting()
and (self.door == nil or self.door:open_percent() == 0)
and not self.forced
then
self.group.set_on(false) self.group.set_on(false)
end end
end end
end, end,
light_callback = function(self, on) light_callback = function(self, on)
if on and self.trash:open_percent() == 0 and self.door:open_percent() == 0 then if
on
and (self.trash == nil or self.trash:open_percent()) == 0
and (self.door == nil or self.door:open_percent() == 0)
then
-- If the door and trash are not open, that means the light got turned on manually -- If the door and trash are not open, that means the light got turned on manually
self.timeout:cancel() self.timeout:cancel()
self.forced = true self.forced = true
@@ -474,7 +485,7 @@ local hallway_storage = LightBrightness.new({
end, end,
}) })
turn_off_when_away(hallway_storage) turn_off_when_away(hallway_storage)
automation.device_manager:add(hallway_storage) device_manager:add(hallway_storage)
local hallway_bottom_lights = HueGroup.new({ local hallway_bottom_lights = HueGroup.new({
identifier = "hallway_bottom_lights", identifier = "hallway_bottom_lights",
@@ -483,7 +494,7 @@ local hallway_bottom_lights = HueGroup.new({
group_id = 81, group_id = 81,
scene_id = "3qWKxGVadXFFG4o", scene_id = "3qWKxGVadXFFG4o",
}) })
automation.device_manager:add(hallway_bottom_lights) device_manager:add(hallway_bottom_lights)
hallway_light_automation.group = { hallway_light_automation.group = {
set_on = function(on) set_on = function(on)
@@ -507,7 +518,7 @@ setmetatable(frontdoor_presence, {
if not presence_system:overall_presence() then if not presence_system:overall_presence() then
mqtt_client:send_message(mqtt_automation("presence/contact/frontdoor"), { mqtt_client:send_message(mqtt_automation("presence/contact/frontdoor"), {
state = true, state = true,
updated = automation.util.get_epoch(), updated = utils.get_epoch(),
}) })
end end
else else
@@ -518,7 +529,7 @@ setmetatable(frontdoor_presence, {
end, end,
}) })
automation.device_manager:add(IkeaRemote.new({ device_manager:add(IkeaRemote.new({
name = "Remote", name = "Remote",
room = "Hallway", room = "Hallway",
client = mqtt_client, client = mqtt_client,
@@ -544,7 +555,7 @@ local hallway_frontdoor = ContactSensor.new({
end, end,
battery_callback = check_battery, battery_callback = check_battery,
}) })
automation.device_manager:add(hallway_frontdoor) device_manager:add(hallway_frontdoor)
hallway_light_automation.door = hallway_frontdoor hallway_light_automation.door = hallway_frontdoor
local hallway_trash = ContactSensor.new({ local hallway_trash = ContactSensor.new({
@@ -558,7 +569,7 @@ local hallway_trash = ContactSensor.new({
end, end,
battery_callback = check_battery, battery_callback = check_battery,
}) })
automation.device_manager:add(hallway_trash) device_manager:add(hallway_trash)
hallway_light_automation.trash = hallway_trash hallway_light_automation.trash = hallway_trash
local guest_light = LightOnOff.new({ local guest_light = LightOnOff.new({
@@ -568,14 +579,14 @@ local guest_light = LightOnOff.new({
client = mqtt_client, client = mqtt_client,
}) })
turn_off_when_away(guest_light) turn_off_when_away(guest_light)
automation.device_manager:add(guest_light) device_manager:add(guest_light)
local bedroom_air_filter = AirFilter.new({ local bedroom_air_filter = AirFilter.new({
name = "Air Filter", name = "Air Filter",
room = "Bedroom", room = "Bedroom",
url = "http://10.0.0.103", url = "http://10.0.0.103",
}) })
automation.device_manager:add(bedroom_air_filter) device_manager:add(bedroom_air_filter)
local bedroom_lights = HueGroup.new({ local bedroom_lights = HueGroup.new({
identifier = "bedroom_lights", identifier = "bedroom_lights",
@@ -584,7 +595,7 @@ local bedroom_lights = HueGroup.new({
group_id = 3, group_id = 3,
scene_id = "PvRs-lGD4VRytL9", scene_id = "PvRs-lGD4VRytL9",
}) })
automation.device_manager:add(bedroom_lights) device_manager:add(bedroom_lights)
local bedroom_lights_relax = HueGroup.new({ local bedroom_lights_relax = HueGroup.new({
identifier = "bedroom_lights", identifier = "bedroom_lights",
ip = hue_ip, ip = hue_ip,
@@ -592,9 +603,9 @@ local bedroom_lights_relax = HueGroup.new({
group_id = 3, group_id = 3,
scene_id = "60tfTyR168v2csz", scene_id = "60tfTyR168v2csz",
}) })
automation.device_manager:add(bedroom_lights_relax) device_manager:add(bedroom_lights_relax)
automation.device_manager:add(HueSwitch.new({ device_manager:add(HueSwitch.new({
name = "Switch", name = "Switch",
room = "Bedroom", room = "Bedroom",
client = mqtt_client, client = mqtt_client,
@@ -608,7 +619,7 @@ automation.device_manager:add(HueSwitch.new({
battery_callback = check_battery, battery_callback = check_battery,
})) }))
automation.device_manager:add(ContactSensor.new({ device_manager:add(ContactSensor.new({
name = "Balcony", name = "Balcony",
room = "Living Room", room = "Living Room",
sensor_type = "Door", sensor_type = "Door",
@@ -616,21 +627,21 @@ automation.device_manager:add(ContactSensor.new({
client = mqtt_client, client = mqtt_client,
battery_callback = check_battery, battery_callback = check_battery,
})) }))
automation.device_manager:add(ContactSensor.new({ device_manager:add(ContactSensor.new({
name = "Window", name = "Window",
room = "Living Room", room = "Living Room",
topic = mqtt_z2m("living/window"), topic = mqtt_z2m("living/window"),
client = mqtt_client, client = mqtt_client,
battery_callback = check_battery, battery_callback = check_battery,
})) }))
automation.device_manager:add(ContactSensor.new({ device_manager:add(ContactSensor.new({
name = "Window", name = "Window",
room = "Bedroom", room = "Bedroom",
topic = mqtt_z2m("bedroom/window"), topic = mqtt_z2m("bedroom/window"),
client = mqtt_client, client = mqtt_client,
battery_callback = check_battery, battery_callback = check_battery,
})) }))
automation.device_manager:add(ContactSensor.new({ device_manager:add(ContactSensor.new({
name = "Window", name = "Window",
room = "Guest Room", room = "Guest Room",
topic = mqtt_z2m("guest/window"), topic = mqtt_z2m("guest/window"),
@@ -645,9 +656,9 @@ local storage_light = LightBrightness.new({
client = mqtt_client, client = mqtt_client,
}) })
turn_off_when_away(storage_light) turn_off_when_away(storage_light)
automation.device_manager:add(storage_light) device_manager:add(storage_light)
automation.device_manager:add(ContactSensor.new({ device_manager:add(ContactSensor.new({
name = "Door", name = "Door",
room = "Storage", room = "Storage",
sensor_type = "Door", sensor_type = "Door",
@@ -663,9 +674,11 @@ automation.device_manager:add(ContactSensor.new({
battery_callback = check_battery, battery_callback = check_battery,
})) }))
automation.device_manager:schedule("0 0 19 * * *", function() device_manager:schedule("0 0 19 * * *", function()
bedroom_air_filter:set_on(true) bedroom_air_filter:set_on(true)
end) end)
automation.device_manager:schedule("0 0 20 * * *", function() device_manager:schedule("0 0 20 * * *", function()
bedroom_air_filter:set_on(false) bedroom_air_filter:set_on(false)
end) end)
return fulfillment

View File

@@ -3,15 +3,13 @@ name = "google_home"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
async-trait = { workspace = true }
automation_cast = { workspace = true } automation_cast = { workspace = true }
futures = { workspace = true }
google_home_macro = { workspace = true } google_home_macro = { workspace = true }
json_value_merge = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
tokio = { workspace = true } tokio = { workspace = true }
async-trait = { workspace = true }
futures = { workspace = true }
json_value_merge = { workspace = true }

View File

@@ -6,7 +6,6 @@ use std::path::Path;
use std::process; use std::process;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use anyhow::anyhow;
use automation_lib::config::{FulfillmentConfig, MqttConfig}; use automation_lib::config::{FulfillmentConfig, MqttConfig};
use automation_lib::device_manager::DeviceManager; use automation_lib::device_manager::DeviceManager;
use automation_lib::helpers; use automation_lib::helpers;
@@ -77,100 +76,93 @@ async fn app() -> anyhow::Result<()> {
// Setup the device handler // Setup the device handler
let device_manager = DeviceManager::new().await; let device_manager = DeviceManager::new().await;
let fulfillment_config = { let lua = mlua::Lua::new();
let lua = mlua::Lua::new();
lua.set_warning_function(|_lua, text, _cont| { lua.set_warning_function(|_lua, text, _cont| {
warn!("{text}"); warn!("{text}");
Ok(()) Ok(())
}); });
let print = lua.create_function(|lua, values: mlua::Variadic<mlua::Value>| { let print = lua.create_function(|lua, values: mlua::Variadic<mlua::Value>| {
// Fortmat the values the same way lua does by default // Fortmat the values the same way lua does by default
let text: String = values let text: String = values
.iter() .iter()
.map(|value| { .map(|value| {
value.to_string().unwrap_or_else(|_| { value.to_string().unwrap_or_else(|_| {
format!("{}: {}", value.type_name(), value.to_pointer().addr()) format!("{}: {}", value.type_name(), value.to_pointer().addr())
})
}) })
.intersperse("\t".to_owned()) })
.collect(); .intersperse("\t".to_owned())
.collect();
// Level 1 of the stack gives us the location that called this function // Level 1 of the stack gives us the location that called this function
let stack = lua.inspect_stack(1).unwrap(); let (file, line) = lua
let file = stack.source().short_src.unwrap_or("?".into()); .inspect_stack(1, |debug| {
let line = stack.curr_line(); (
debug
.source()
.short_src
.unwrap_or("???".into())
.into_owned(),
debug.current_line().unwrap_or(0),
)
})
.unwrap();
// The target is overridden to make it possible to filter for logs originating from the // The target is overridden to make it possible to filter for logs originating from the
// config // config
info!(target: "automation_config", %file, line, "{text}"); info!(target: "automation_config", %file, line, "{text}");
Ok(()) Ok(())
})?; })?;
lua.globals().set("print", print)?; lua.globals().set("print", print)?;
let automation = lua.create_table()?; let mqtt = lua.create_table()?;
let event_channel = device_manager.event_channel(); let event_channel = device_manager.event_channel();
let new_mqtt_client = lua.create_function(move |lua, config: mlua::Value| { let mqtt_new = lua.create_function(move |lua, config: mlua::Value| {
let config: MqttConfig = lua.from_value(config)?; let config: MqttConfig = lua.from_value(config)?;
// Create a mqtt client // Create a mqtt client
// TODO: When starting up, the devices are not yet created, this could lead to a device being out of sync // TODO: When starting up, the devices are not yet created, this could lead to a device being out of sync
let (client, eventloop) = AsyncClient::new(config.into(), 100); let (client, eventloop) = AsyncClient::new(config.into(), 100);
mqtt::start(eventloop, &event_channel); mqtt::start(eventloop, &event_channel);
Ok(WrappedAsyncClient(client)) Ok(WrappedAsyncClient(client))
})?; })?;
mqtt.set("new", mqtt_new)?;
lua.register_module("mqtt", mqtt)?;
automation.set("new_mqtt_client", new_mqtt_client)?; lua.register_module("device_manager", device_manager.clone())?;
automation.set("device_manager", device_manager.clone())?;
let util = lua.create_table()?; let utils = lua.create_table()?;
let get_env = lua.create_function(|_lua, name: String| { let get_env = lua.create_function(|_lua, name: String| {
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)?; utils.set("get_env", get_env)?;
let get_hostname = lua.create_function(|_lua, ()| { let get_hostname = lua.create_function(|_lua, ()| {
hostname::get() hostname::get()
.map(|name| name.to_str().unwrap_or("unknown").to_owned()) .map(|name| name.to_str().unwrap_or("unknown").to_owned())
.map_err(mlua::ExternalError::into_lua_err) .map_err(mlua::ExternalError::into_lua_err)
})?; })?;
util.set("get_hostname", get_hostname)?; utils.set("get_hostname", get_hostname)?;
let get_epoch = lua.create_function(|_lua, ()| { let get_epoch = lua.create_function(|_lua, ()| {
Ok(SystemTime::now() Ok(SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.expect("Time is after UNIX EPOCH") .expect("Time is after UNIX EPOCH")
.as_millis()) .as_millis())
})?; })?;
util.set("get_epoch", get_epoch)?; utils.set("get_epoch", get_epoch)?;
automation.set("util", util)?;
lua.globals().set("automation", automation)?; lua.register_module("utils", utils)?;
automation_devices::register_with_lua(&lua)?; automation_devices::register_with_lua(&lua)?;
helpers::register_with_lua(&lua)?; helpers::register_with_lua(&lua)?;
// TODO: Make this not hardcoded // TODO: Make this not hardcoded
let config_filename = std::env::var("AUTOMATION_CONFIG").unwrap_or("./config.lua".into()); let config_filename = std::env::var("AUTOMATION_CONFIG").unwrap_or("./config.lua".into());
let config_path = Path::new(&config_filename); let config_path = Path::new(&config_filename);
match lua.load(config_path).exec_async().await {
Err(error) => {
println!("{error}");
Err(error)
}
result => result,
}?;
let automation: mlua::Table = lua.globals().get("automation")?; let fulfillment_config: mlua::Value = lua.load(config_path).eval_async().await?;
let fulfillment_config: Option<mlua::Value> = automation.get("fulfillment")?; let fulfillment_config: FulfillmentConfig = lua.from_value(fulfillment_config)?;
if let Some(fulfillment_config) = fulfillment_config {
let fulfillment_config: FulfillmentConfig = lua.from_value(fulfillment_config)?;
debug!("automation.fulfillment = {fulfillment_config:?}");
fulfillment_config
} else {
return Err(anyhow!("Fulfillment is not configured"));
}
};
// Create google home fulfillment route // Create google home fulfillment route
let fulfillment = Router::new().route("/google_home", post(fulfillment)); let fulfillment = Router::new().route("/google_home", post(fulfillment));

View File

@@ -1,6 +1,5 @@
use std::result; use std::result;
use axum::async_trait;
use axum::extract::{FromRef, FromRequestParts}; use axum::extract::{FromRef, FromRequestParts};
use axum::http::StatusCode; use axum::http::StatusCode;
use axum::http::request::Parts; use axum::http::request::Parts;
@@ -79,7 +78,6 @@ pub struct User {
pub preferred_username: String, pub preferred_username: String,
} }
#[async_trait]
impl<S> FromRequestParts<S> for User impl<S> FromRequestParts<S> for User
where where
String: FromRef<S>, String: FromRef<S>,
@@ -116,7 +114,7 @@ where
.await .await
.map_err(|err| ApiError::new(StatusCode::INTERNAL_SERVER_ERROR, err.into()))?; .map_err(|err| ApiError::new(StatusCode::INTERNAL_SERVER_ERROR, err.into()))?;
return Ok(user); Ok(user)
} else { } else {
let err: ApiErrorJson = res let err: ApiErrorJson = res
.json() .json()