Compare commits
12 Commits
7a9f464e61
...
0976798adf
| Author | SHA1 | Date | |
|---|---|---|---|
|
0976798adf
|
|||
|
7ffff845c6
|
|||
|
8a977907e7
|
|||
|
322378a64e
|
|||
|
ffd44771a5
|
|||
|
15189db1ce
|
|||
|
c4ab3763d8
|
|||
|
9ee0f4eb5c
|
|||
|
c17e7b0481
|
|||
|
afef100aac
|
|||
|
d3f9feb96f
|
|||
|
4a83250258
|
@@ -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
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
[default.extend-words]
|
|
||||||
mosquitto = "mosquitto"
|
|
||||||
246
Cargo.lock
generated
246
Cargo.lock
generated
@@ -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"
|
||||||
|
|||||||
110
Cargo.toml
110
Cargo.toml
@@ -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"
|
||||||
|
|||||||
@@ -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]
|
||||||
|
|||||||
@@ -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 }
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ pub struct Config {
|
|||||||
|
|
||||||
#[device_config(from_lua, default)]
|
#[device_config(from_lua, default)]
|
||||||
pub callback: ActionCallback<ContactSensor, bool>,
|
pub callback: ActionCallback<ContactSensor, bool>,
|
||||||
|
#[device_config(from_lua, default)]
|
||||||
|
pub battery_callback: ActionCallback<ContactSensor, f32>,
|
||||||
|
|
||||||
#[device_config(from_lua)]
|
#[device_config(from_lua)]
|
||||||
pub client: WrappedAsyncClient,
|
pub client: WrappedAsyncClient,
|
||||||
}
|
}
|
||||||
@@ -149,21 +152,27 @@ impl OnMqtt for ContactSensor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_closed = match ContactMessage::try_from(message) {
|
let message = match ContactMessage::try_from(message) {
|
||||||
Ok(state) => state.is_closed(),
|
Ok(message) => message,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(id = self.get_id(), "Failed to parse message: {err}");
|
error!(id = self.get_id(), "Failed to parse message: {err}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_closed == self.state().await.is_closed {
|
if let Some(is_closed) = message.contact {
|
||||||
return;
|
if is_closed == self.state().await.is_closed {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.config.callback.call(self, &!is_closed).await;
|
||||||
|
|
||||||
|
debug!(id = self.get_id(), "Updating state to {is_closed}");
|
||||||
|
self.state_mut().await.is_closed = is_closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.config.callback.call(self, &!is_closed).await;
|
if let Some(battery) = message.battery {
|
||||||
|
self.config.battery_callback.call(self, &battery).await;
|
||||||
debug!(id = self.get_id(), "Updating state to {is_closed}");
|
}
|
||||||
self.state_mut().await.is_closed = is_closed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ impl AddAdditionalMethods for HueBridge {
|
|||||||
{
|
{
|
||||||
methods.add_async_method(
|
methods.add_async_method(
|
||||||
"set_flag",
|
"set_flag",
|
||||||
|lua, this, (flag, value): (mlua::Value, bool)| async move {
|
async |lua, this, (flag, value): (mlua::Value, bool)| {
|
||||||
let flag: Flag = lua.from_value(flag)?;
|
let flag: Flag = lua.from_value(flag)?;
|
||||||
|
|
||||||
this.set_flag(flag, value).await;
|
this.set_flag(flag, value).await;
|
||||||
|
|||||||
@@ -31,9 +31,12 @@ pub struct Config {
|
|||||||
|
|
||||||
#[device_config(from_lua, default)]
|
#[device_config(from_lua, default)]
|
||||||
pub right_hold_callback: ActionCallback<HueSwitch, ()>,
|
pub right_hold_callback: ActionCallback<HueSwitch, ()>,
|
||||||
|
|
||||||
|
#[device_config(from_lua, default)]
|
||||||
|
pub battery_callback: ActionCallback<HueSwitch, f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Copy, Clone, Deserialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
enum Action {
|
enum Action {
|
||||||
LeftPress,
|
LeftPress,
|
||||||
@@ -48,7 +51,8 @@ enum Action {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
struct State {
|
struct State {
|
||||||
action: Action,
|
action: Option<Action>,
|
||||||
|
battery: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, LuaDevice)]
|
#[derive(Debug, Clone, LuaDevice)]
|
||||||
@@ -84,32 +88,43 @@ impl OnMqtt for HueSwitch {
|
|||||||
async fn on_mqtt(&self, message: Publish) {
|
async fn on_mqtt(&self, message: Publish) {
|
||||||
// Check if the message is from the device itself or from a remote
|
// Check if the message is from the device itself or from a remote
|
||||||
if matches(&message.topic, &self.config.mqtt.topic) {
|
if matches(&message.topic, &self.config.mqtt.topic) {
|
||||||
let action = match serde_json::from_slice::<State>(&message.payload) {
|
let message = match serde_json::from_slice::<State>(&message.payload) {
|
||||||
Ok(message) => message.action,
|
Ok(message) => message,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(id = Device::get_id(self), "Failed to parse message: {err}");
|
warn!(id = Device::get_id(self), "Failed to parse message: {err}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
debug!(id = Device::get_id(self), "Remote action = {:?}", action);
|
|
||||||
|
|
||||||
match action {
|
if let Some(action) = message.action {
|
||||||
Action::LeftPressRelease => self.config.left_callback.call(self, &()).await,
|
debug!(
|
||||||
Action::RightPressRelease => self.config.right_callback.call(self, &()).await,
|
id = Device::get_id(self),
|
||||||
Action::LeftHold => self.config.left_hold_callback.call(self, &()).await,
|
?message.action,
|
||||||
Action::RightHold => self.config.right_hold_callback.call(self, &()).await,
|
"Action received",
|
||||||
// If there is no hold action, the switch will act like a normal release
|
);
|
||||||
Action::RightHoldRelease => {
|
|
||||||
if !self.config.right_hold_callback.is_set() {
|
match action {
|
||||||
self.config.right_callback.call(self, &()).await
|
Action::LeftPressRelease => self.config.left_callback.call(self, &()).await,
|
||||||
|
Action::RightPressRelease => self.config.right_callback.call(self, &()).await,
|
||||||
|
Action::LeftHold => self.config.left_hold_callback.call(self, &()).await,
|
||||||
|
Action::RightHold => self.config.right_hold_callback.call(self, &()).await,
|
||||||
|
// If there is no hold action, the switch will act like a normal release
|
||||||
|
Action::RightHoldRelease => {
|
||||||
|
if !self.config.right_hold_callback.is_set() {
|
||||||
|
self.config.right_callback.call(self, &()).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
Action::LeftHoldRelease => {
|
||||||
Action::LeftHoldRelease => {
|
if !self.config.left_hold_callback.is_set() {
|
||||||
if !self.config.left_hold_callback.is_set() {
|
self.config.left_callback.call(self, &()).await
|
||||||
self.config.left_callback.call(self, &()).await
|
}
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
|
|
||||||
|
if let Some(battery) = message.battery {
|
||||||
|
self.config.battery_callback.call(self, &battery).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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};
|
||||||
|
|
||||||
@@ -25,6 +25,8 @@ pub struct Config {
|
|||||||
|
|
||||||
#[device_config(from_lua)]
|
#[device_config(from_lua)]
|
||||||
pub callback: ActionCallback<IkeaRemote, bool>,
|
pub callback: ActionCallback<IkeaRemote, bool>,
|
||||||
|
#[device_config(from_lua, default)]
|
||||||
|
pub battery_callback: ActionCallback<IkeaRemote, f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, LuaDevice)]
|
#[derive(Debug, Clone, LuaDevice)]
|
||||||
@@ -60,31 +62,38 @@ impl OnMqtt for IkeaRemote {
|
|||||||
async fn on_mqtt(&self, message: Publish) {
|
async fn on_mqtt(&self, message: Publish) {
|
||||||
// Check if the message is from the deviec itself or from a remote
|
// Check if the message is from the deviec itself or from a remote
|
||||||
if matches(&message.topic, &self.config.mqtt.topic) {
|
if matches(&message.topic, &self.config.mqtt.topic) {
|
||||||
let action = match RemoteMessage::try_from(message) {
|
let message = match RemoteMessage::try_from(message) {
|
||||||
Ok(message) => message.action(),
|
Ok(message) => message,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(id = Device::get_id(self), "Failed to parse message: {err}");
|
error!(id = Device::get_id(self), "Failed to parse message: {err}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
debug!(id = Device::get_id(self), "Remote action = {:?}", action);
|
|
||||||
|
|
||||||
let on = if self.config.single_button {
|
if let Some(action) = message.action {
|
||||||
match action {
|
debug!(id = Device::get_id(self), "Remote action = {:?}", action);
|
||||||
RemoteAction::On => Some(true),
|
|
||||||
RemoteAction::BrightnessMoveUp => Some(false),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
match action {
|
|
||||||
RemoteAction::On => Some(true),
|
|
||||||
RemoteAction::Off => Some(false),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(on) = on {
|
let on = if self.config.single_button {
|
||||||
self.config.callback.call(self, &on).await;
|
match action {
|
||||||
|
RemoteAction::On => Some(true),
|
||||||
|
RemoteAction::BrightnessMoveUp => Some(false),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match action {
|
||||||
|
RemoteAction::On => Some(true),
|
||||||
|
RemoteAction::Off => Some(false),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(on) = on {
|
||||||
|
self.config.callback.call(self, &on).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(battery) = message.battery {
|
||||||
|
self.config.battery_callback.call(self, &battery).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ impl AddAdditionalMethods for Ntfy {
|
|||||||
{
|
{
|
||||||
methods.add_async_method(
|
methods.add_async_method(
|
||||||
"send_notification",
|
"send_notification",
|
||||||
|lua, this, notification: mlua::Value| async move {
|
async |lua, this, notification: mlua::Value| {
|
||||||
let notification: Notification = lua.from_value(notification)?;
|
let notification: Notification = lua.from_value(notification)?;
|
||||||
|
|
||||||
this.send(notification).await;
|
this.send(notification).await;
|
||||||
|
|||||||
@@ -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 }
|
|
||||||
|
|||||||
@@ -73,22 +73,19 @@ impl DeviceManager {
|
|||||||
match event {
|
match event {
|
||||||
Event::MqttMessage(message) => {
|
Event::MqttMessage(message) => {
|
||||||
let devices = self.devices.read().await;
|
let devices = self.devices.read().await;
|
||||||
let iter = devices.iter().map(|(id, device)| {
|
let iter = devices.iter().map(async |(id, device)| {
|
||||||
let message = message.clone();
|
let device: Option<&dyn OnMqtt> = device.cast();
|
||||||
async move {
|
if let Some(device) = device {
|
||||||
let device: Option<&dyn OnMqtt> = device.cast();
|
// let subscribed = device
|
||||||
if let Some(device) = device {
|
// .topics()
|
||||||
// let subscribed = device
|
// .iter()
|
||||||
// .topics()
|
// .any(|topic| matches(&message.topic, topic));
|
||||||
// .iter()
|
//
|
||||||
// .any(|topic| matches(&message.topic, topic));
|
// if subscribed {
|
||||||
//
|
trace!(id, "Handling");
|
||||||
// if subscribed {
|
device.on_mqtt(message.clone()).await;
|
||||||
trace!(id, "Handling");
|
trace!(id, "Done");
|
||||||
device.on_mqtt(message).await;
|
// }
|
||||||
trace!(id, "Done");
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -100,7 +97,7 @@ impl DeviceManager {
|
|||||||
|
|
||||||
impl mlua::UserData for DeviceManager {
|
impl mlua::UserData for DeviceManager {
|
||||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||||
methods.add_async_method("add", |_lua, this, device: Box<dyn Device>| async move {
|
methods.add_async_method("add", async |_lua, this, device: Box<dyn Device>| {
|
||||||
this.add(device).await;
|
this.add(device).await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -108,7 +105,7 @@ impl mlua::UserData for DeviceManager {
|
|||||||
|
|
||||||
methods.add_async_method(
|
methods.add_async_method(
|
||||||
"schedule",
|
"schedule",
|
||||||
|lua, this, (schedule, f): (String, mlua::Function)| async move {
|
async |lua, this, (schedule, f): (String, mlua::Function)| {
|
||||||
debug!("schedule = {schedule}");
|
debug!("schedule = {schedule}");
|
||||||
// This creates a function, that returns the actual job we want to run
|
// This creates a function, that returns the actual job we want to run
|
||||||
let create_job = {
|
let create_job = {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ impl mlua::UserData for Timeout {
|
|||||||
|
|
||||||
methods.add_async_method(
|
methods.add_async_method(
|
||||||
"start",
|
"start",
|
||||||
|_lua, this, (timeout, callback): (f32, ActionCallback<mlua::Value, bool>)| async move {
|
async |_lua, this, (timeout, callback): (f32, ActionCallback<mlua::Value, bool>)| {
|
||||||
if let Some(handle) = this.state.write().await.handle.take() {
|
if let Some(handle) = this.state.write().await.handle.take() {
|
||||||
handle.abort();
|
handle.abort();
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ impl mlua::UserData for Timeout {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
methods.add_async_method("cancel", |_lua, this, ()| async move {
|
methods.add_async_method("cancel", async |_lua, this, ()| {
|
||||||
debug!("Canceling timeout callback");
|
debug!("Canceling timeout callback");
|
||||||
|
|
||||||
if let Some(handle) = this.state.write().await.handle.take() {
|
if let Some(handle) = this.state.write().await.handle.take() {
|
||||||
@@ -60,7 +60,7 @@ impl mlua::UserData for Timeout {
|
|||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
methods.add_async_method("is_waiting", |_lua, this, ()| async move {
|
methods.add_async_method("is_waiting", async |_lua, this, ()| {
|
||||||
debug!("Canceling timeout callback");
|
debug!("Canceling timeout callback");
|
||||||
|
|
||||||
if let Some(handle) = this.state.read().await.handle.as_ref() {
|
if let Some(handle) = this.state.read().await.handle.as_ref() {
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ pub trait OnOff {
|
|||||||
where
|
where
|
||||||
Self: Sized + google_home::traits::OnOff + 'static,
|
Self: Sized + google_home::traits::OnOff + 'static,
|
||||||
{
|
{
|
||||||
methods.add_async_method("set_on", |_lua, this, on: bool| async move {
|
methods.add_async_method("set_on", async |_lua, this, on: bool| {
|
||||||
this.deref().set_on(on).await.unwrap();
|
this.deref().set_on(on).await.unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
methods.add_async_method("on", |_lua, this, ()| async move {
|
methods.add_async_method("on", async |_lua, this, ()| {
|
||||||
Ok(this.deref().on().await.unwrap())
|
Ok(this.deref().on().await.unwrap())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -25,13 +25,13 @@ pub trait Brightness {
|
|||||||
where
|
where
|
||||||
Self: Sized + google_home::traits::Brightness + 'static,
|
Self: Sized + google_home::traits::Brightness + 'static,
|
||||||
{
|
{
|
||||||
methods.add_async_method("set_brightness", |_lua, this, brightness: u8| async move {
|
methods.add_async_method("set_brightness", async |_lua, this, brightness: u8| {
|
||||||
this.set_brightness(brightness).await.unwrap();
|
this.set_brightness(brightness).await.unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
methods.add_async_method("brightness", |_lua, this, _: ()| async move {
|
methods.add_async_method("brightness", async |_lua, this, _: ()| {
|
||||||
Ok(this.brightness().await.unwrap())
|
Ok(this.brightness().await.unwrap())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ pub trait ColorSetting {
|
|||||||
{
|
{
|
||||||
methods.add_async_method(
|
methods.add_async_method(
|
||||||
"set_color_temperature",
|
"set_color_temperature",
|
||||||
|_lua, this, temperature: u32| async move {
|
async |_lua, this, temperature: u32| {
|
||||||
this.set_color(google_home::traits::Color { temperature })
|
this.set_color(google_home::traits::Color { temperature })
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -54,7 +54,7 @@ pub trait ColorSetting {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
methods.add_async_method("color_temperature", |_lua, this, ()| async move {
|
methods.add_async_method("color_temperature", async |_lua, this, ()| {
|
||||||
Ok(this.color().await.temperature)
|
Ok(this.color().await.temperature)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -66,16 +66,13 @@ pub trait OpenClose {
|
|||||||
where
|
where
|
||||||
Self: Sized + google_home::traits::OpenClose + 'static,
|
Self: Sized + google_home::traits::OpenClose + 'static,
|
||||||
{
|
{
|
||||||
methods.add_async_method(
|
methods.add_async_method("set_open_percent", async |_lua, this, open_percent: u8| {
|
||||||
"set_open_percent",
|
this.set_open_percent(open_percent).await.unwrap();
|
||||||
|_lua, this, open_percent: u8| async move {
|
|
||||||
this.set_open_percent(open_percent).await.unwrap();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
methods.add_async_method("open_percent", |_lua, this, _: ()| async move {
|
methods.add_async_method("open_percent", async |_lua, this, _: ()| {
|
||||||
Ok(this.open_percent().await.unwrap())
|
Ok(this.open_percent().await.unwrap())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,13 +68,8 @@ pub enum RemoteAction {
|
|||||||
// Message used to report the action performed by a remote
|
// Message used to report the action performed by a remote
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct RemoteMessage {
|
pub struct RemoteMessage {
|
||||||
action: RemoteAction,
|
pub action: Option<RemoteAction>,
|
||||||
}
|
pub battery: Option<f32>,
|
||||||
|
|
||||||
impl RemoteMessage {
|
|
||||||
pub fn action(&self) -> RemoteAction {
|
|
||||||
self.action
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Publish> for RemoteMessage {
|
impl TryFrom<Publish> for RemoteMessage {
|
||||||
@@ -144,13 +139,8 @@ impl TryFrom<Publish> for BrightnessMessage {
|
|||||||
// Message to report the state of a contact sensor
|
// Message to report the state of a contact sensor
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct ContactMessage {
|
pub struct ContactMessage {
|
||||||
contact: bool,
|
pub contact: Option<bool>,
|
||||||
}
|
pub battery: Option<f32>,
|
||||||
|
|
||||||
impl ContactMessage {
|
|
||||||
pub fn is_closed(&self) -> bool {
|
|
||||||
self.contact
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Publish> for ContactMessage {
|
impl TryFrom<Publish> for ContactMessage {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ impl mlua::UserData for WrappedAsyncClient {
|
|||||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||||
methods.add_async_method(
|
methods.add_async_method(
|
||||||
"send_message",
|
"send_message",
|
||||||
|_lua, this, (topic, message): (String, mlua::Value)| async move {
|
async |_lua, this, (topic, message): (String, mlua::Value)| {
|
||||||
let message = serde_json::to_string(&message).unwrap();
|
let message = serde_json::to_string(&message).unwrap();
|
||||||
|
|
||||||
debug!("message = {message}");
|
debug!("message = {message}");
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ impl Impl {
|
|||||||
quote! {
|
quote! {
|
||||||
impl mlua::UserData for #name #generics {
|
impl mlua::UserData for #name #generics {
|
||||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||||
methods.add_async_function("new", |_lua, config| async {
|
methods.add_async_function("new", async |_lua, config| {
|
||||||
let device: Self = LuaDeviceCreate::create(config)
|
let device: Self = LuaDeviceCreate::create(config)
|
||||||
.await
|
.await
|
||||||
.map_err(mlua::ExternalError::into_lua_err)?;
|
.map_err(mlua::ExternalError::into_lua_err)?;
|
||||||
@@ -58,7 +58,7 @@ impl Impl {
|
|||||||
Ok(b)
|
Ok(b)
|
||||||
});
|
});
|
||||||
|
|
||||||
methods.add_async_method("get_id", |_lua, this, _: ()| async move { Ok(this.get_id()) });
|
methods.add_async_method("get_id", async |_lua, this, _: ()| { Ok(this.get_id()) });
|
||||||
|
|
||||||
#(
|
#(
|
||||||
#traits::add_methods(methods);
|
#traits::add_methods(methods);
|
||||||
|
|||||||
168
config.lua
168
config.lua
@@ -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,54 @@ 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 function check_battery(device, battery)
|
||||||
|
local id = device:get_id()
|
||||||
|
if battery < 15 then
|
||||||
|
print("Device '" .. id .. "' has low battery: " .. tostring(battery))
|
||||||
|
low_battery[id] = battery
|
||||||
|
else
|
||||||
|
low_battery[id] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
device_manager:schedule("0 0 21 */1 * *", function()
|
||||||
|
-- Don't send notifications if there are now devices with low battery
|
||||||
|
if next(low_battery) == nil then
|
||||||
|
print("No devices with low battery")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local lines = {}
|
||||||
|
for name, battery in pairs(low_battery) do
|
||||||
|
table.insert(lines, name .. ": " .. tostring(battery) .. "%")
|
||||||
|
end
|
||||||
|
local message = table.concat(lines, "\n")
|
||||||
|
|
||||||
|
ntfy:send_notification({
|
||||||
|
title = "Low battery",
|
||||||
|
message = message,
|
||||||
|
tags = { "battery" },
|
||||||
|
priority = "default",
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
local on_presence = {
|
local on_presence = {
|
||||||
add = function(self, f)
|
add = function(self, f)
|
||||||
@@ -51,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",
|
||||||
@@ -74,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)
|
||||||
|
|
||||||
@@ -91,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,
|
||||||
@@ -108,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",
|
||||||
@@ -124,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)
|
||||||
@@ -139,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,
|
||||||
@@ -147,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,
|
||||||
@@ -155,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,
|
||||||
@@ -171,9 +205,10 @@ automation.device_manager:add(HueSwitch.new({
|
|||||||
right_hold_callback = function()
|
right_hold_callback = function()
|
||||||
living_lights_relax:set_on(true)
|
living_lights_relax:set_on(true)
|
||||||
end,
|
end,
|
||||||
|
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"),
|
||||||
@@ -189,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",
|
||||||
@@ -197,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,
|
||||||
@@ -222,6 +257,7 @@ automation.device_manager:add(IkeaRemote.new({
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
battery_callback = check_battery,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
local function kettle_timeout()
|
local function kettle_timeout()
|
||||||
@@ -247,28 +283,30 @@ 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,
|
||||||
topic = mqtt_z2m("bedroom/remote"),
|
topic = mqtt_z2m("bedroom/remote"),
|
||||||
single_button = true,
|
single_button = true,
|
||||||
callback = set_kettle,
|
callback = set_kettle,
|
||||||
|
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,
|
||||||
topic = mqtt_z2m("kitchen/remote"),
|
topic = mqtt_z2m("kitchen/remote"),
|
||||||
single_button = true,
|
single_button = true,
|
||||||
callback = set_kettle,
|
callback = set_kettle,
|
||||||
|
battery_callback = check_battery,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
local function off_timeout(duration)
|
local function off_timeout(duration)
|
||||||
@@ -292,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,
|
||||||
@@ -309,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"),
|
||||||
@@ -324,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",
|
||||||
@@ -333,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,
|
||||||
@@ -356,6 +394,7 @@ automation.device_manager:add(IkeaRemote.new({
|
|||||||
workbench_light:set_on(false)
|
workbench_light:set_on(false)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
battery_callback = check_battery,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
local hallway_top_light = HueGroup.new({
|
local hallway_top_light = HueGroup.new({
|
||||||
@@ -365,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,
|
||||||
@@ -373,8 +412,9 @@ automation.device_manager:add(HueSwitch.new({
|
|||||||
left_callback = function()
|
left_callback = function()
|
||||||
hallway_top_light:set_on(not hallway_top_light:on())
|
hallway_top_light:set_on(not hallway_top_light:on())
|
||||||
end,
|
end,
|
||||||
|
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,
|
||||||
@@ -382,6 +422,7 @@ automation.device_manager:add(HueSwitch.new({
|
|||||||
left_callback = function()
|
left_callback = function()
|
||||||
hallway_top_light:set_on(not hallway_top_light:on())
|
hallway_top_light:set_on(not hallway_top_light:on())
|
||||||
end,
|
end,
|
||||||
|
battery_callback = check_battery,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
local hallway_light_automation = {
|
local hallway_light_automation = {
|
||||||
@@ -399,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)
|
||||||
@@ -409,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
|
||||||
@@ -436,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",
|
||||||
@@ -445,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)
|
||||||
@@ -469,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
|
||||||
@@ -480,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,
|
||||||
@@ -488,6 +537,7 @@ automation.device_manager:add(IkeaRemote.new({
|
|||||||
callback = function(_, on)
|
callback = function(_, on)
|
||||||
hallway_light_automation:switch_callback(on)
|
hallway_light_automation:switch_callback(on)
|
||||||
end,
|
end,
|
||||||
|
battery_callback = check_battery,
|
||||||
}))
|
}))
|
||||||
local hallway_frontdoor = ContactSensor.new({
|
local hallway_frontdoor = ContactSensor.new({
|
||||||
name = "Frontdoor",
|
name = "Frontdoor",
|
||||||
@@ -503,8 +553,9 @@ local hallway_frontdoor = ContactSensor.new({
|
|||||||
hallway_light_automation:door_callback(open)
|
hallway_light_automation:door_callback(open)
|
||||||
frontdoor_presence(open)
|
frontdoor_presence(open)
|
||||||
end,
|
end,
|
||||||
|
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({
|
||||||
@@ -516,8 +567,9 @@ local hallway_trash = ContactSensor.new({
|
|||||||
callback = function(_, open)
|
callback = function(_, open)
|
||||||
hallway_light_automation:trash_callback(open)
|
hallway_light_automation:trash_callback(open)
|
||||||
end,
|
end,
|
||||||
|
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({
|
||||||
@@ -527,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",
|
||||||
@@ -543,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,
|
||||||
@@ -551,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,
|
||||||
@@ -564,32 +616,37 @@ automation.device_manager:add(HueSwitch.new({
|
|||||||
left_hold_callback = function()
|
left_hold_callback = function()
|
||||||
bedroom_lights_relax:set_on(true)
|
bedroom_lights_relax:set_on(true)
|
||||||
end,
|
end,
|
||||||
|
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",
|
||||||
topic = mqtt_z2m("living/balcony"),
|
topic = mqtt_z2m("living/balcony"),
|
||||||
client = mqtt_client,
|
client = mqtt_client,
|
||||||
|
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,
|
||||||
}))
|
}))
|
||||||
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,
|
||||||
}))
|
}))
|
||||||
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"),
|
||||||
client = mqtt_client,
|
client = mqtt_client,
|
||||||
|
battery_callback = check_battery,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
local storage_light = LightBrightness.new({
|
local storage_light = LightBrightness.new({
|
||||||
@@ -599,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",
|
||||||
@@ -614,11 +671,14 @@ automation.device_manager:add(ContactSensor.new({
|
|||||||
storage_light:set_on(false)
|
storage_light:set_on(false)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
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
|
||||||
|
|||||||
@@ -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 }
|
|
||||||
|
|||||||
@@ -40,15 +40,13 @@ impl GoogleHome {
|
|||||||
let intent = request.inputs.into_iter().next();
|
let intent = request.inputs.into_iter().next();
|
||||||
|
|
||||||
let payload: OptionFuture<_> = intent
|
let payload: OptionFuture<_> = intent
|
||||||
.map(|intent| async move {
|
.map(async |intent| match intent {
|
||||||
match intent {
|
Intent::Sync => ResponsePayload::Sync(self.sync(devices).await),
|
||||||
Intent::Sync => ResponsePayload::Sync(self.sync(devices).await),
|
Intent::Query(payload) => {
|
||||||
Intent::Query(payload) => {
|
ResponsePayload::Query(self.query(payload, devices).await)
|
||||||
ResponsePayload::Query(self.query(payload, devices).await)
|
}
|
||||||
}
|
Intent::Execute(payload) => {
|
||||||
Intent::Execute(payload) => {
|
ResponsePayload::Execute(self.execute(payload, devices).await)
|
||||||
ResponsePayload::Execute(self.execute(payload, devices).await)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.into();
|
.into();
|
||||||
@@ -64,7 +62,7 @@ impl GoogleHome {
|
|||||||
devices: &HashMap<String, Box<T>>,
|
devices: &HashMap<String, Box<T>>,
|
||||||
) -> sync::Payload {
|
) -> sync::Payload {
|
||||||
let mut resp_payload = sync::Payload::new(&self.user_id);
|
let mut resp_payload = sync::Payload::new(&self.user_id);
|
||||||
let f = devices.values().map(|device| async move {
|
let f = devices.values().map(async |device| {
|
||||||
if let Some(device) = device.as_ref().cast() {
|
if let Some(device) = device.as_ref().cast() {
|
||||||
Some(Device::sync(device).await)
|
Some(Device::sync(device).await)
|
||||||
} else {
|
} else {
|
||||||
@@ -86,7 +84,7 @@ impl GoogleHome {
|
|||||||
.devices
|
.devices
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|device| device.id)
|
.map(|device| device.id)
|
||||||
.map(|id| async move {
|
.map(async |id| {
|
||||||
// NOTE: Requires let_chains feature
|
// NOTE: Requires let_chains feature
|
||||||
let device = if let Some(device) = devices.get(id.as_str())
|
let device = if let Some(device) = devices.get(id.as_str())
|
||||||
&& let Some(device) = device.as_ref().cast()
|
&& let Some(device) = device.as_ref().cast()
|
||||||
@@ -115,84 +113,77 @@ impl GoogleHome {
|
|||||||
) -> execute::Payload {
|
) -> execute::Payload {
|
||||||
let resp_payload = Arc::new(Mutex::new(response::execute::Payload::new()));
|
let resp_payload = Arc::new(Mutex::new(response::execute::Payload::new()));
|
||||||
|
|
||||||
let f = payload.commands.into_iter().map(|command| {
|
let f = payload.commands.into_iter().map(async |command| {
|
||||||
let resp_payload = resp_payload.clone();
|
let mut success = response::execute::Command::new(execute::Status::Success);
|
||||||
async move {
|
success.states = Some(execute::States {
|
||||||
let mut success = response::execute::Command::new(execute::Status::Success);
|
online: true,
|
||||||
success.states = Some(execute::States {
|
state: Default::default(),
|
||||||
online: true,
|
});
|
||||||
state: Default::default(),
|
let mut offline = response::execute::Command::new(execute::Status::Offline);
|
||||||
});
|
offline.states = Some(execute::States {
|
||||||
let mut offline = response::execute::Command::new(execute::Status::Offline);
|
online: false,
|
||||||
offline.states = Some(execute::States {
|
state: Default::default(),
|
||||||
online: false,
|
});
|
||||||
state: Default::default(),
|
let mut errors: HashMap<ErrorCode, response::execute::Command> = HashMap::new();
|
||||||
});
|
|
||||||
let mut errors: HashMap<ErrorCode, response::execute::Command> = HashMap::new();
|
|
||||||
|
|
||||||
let f = command
|
let f = command
|
||||||
.devices
|
.devices
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|device| device.id)
|
.map(|device| device.id)
|
||||||
.map(|id| {
|
.map(async |id| {
|
||||||
let execution = command.execution.clone();
|
if let Some(device) = devices.get(id.as_str())
|
||||||
async move {
|
&& let Some(device) = device.as_ref().cast()
|
||||||
if let Some(device) = devices.get(id.as_str())
|
{
|
||||||
&& let Some(device) = device.as_ref().cast()
|
if !device.is_online().await {
|
||||||
{
|
return (id, Ok(false));
|
||||||
if !device.is_online().await {
|
|
||||||
return (id, Ok(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: We can not use .map here because async =(
|
|
||||||
let mut results = Vec::new();
|
|
||||||
for cmd in &execution {
|
|
||||||
results.push(Device::execute(device, cmd.clone()).await);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert vec of results to a result with a vec and the first
|
|
||||||
// encountered error
|
|
||||||
let results =
|
|
||||||
results.into_iter().collect::<Result<Vec<_>, ErrorCode>>();
|
|
||||||
|
|
||||||
// TODO: We only get one error not all errors
|
|
||||||
if let Err(err) = results {
|
|
||||||
(id, Err(err))
|
|
||||||
} else {
|
|
||||||
(id, Ok(true))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
(id.clone(), Err(DeviceError::DeviceNotFound.into()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
let a = join_all(f).await;
|
// NOTE: We can not use .map here because async =(
|
||||||
a.into_iter().for_each(|(id, state)| {
|
let mut results = Vec::new();
|
||||||
match state {
|
for cmd in &command.execution {
|
||||||
Ok(true) => success.add_id(&id),
|
results.push(Device::execute(device, cmd.clone()).await);
|
||||||
Ok(false) => offline.add_id(&id),
|
}
|
||||||
Err(err) => errors
|
|
||||||
.entry(err)
|
// Convert vec of results to a result with a vec and the first
|
||||||
.or_insert_with(|| match &err {
|
// encountered error
|
||||||
ErrorCode::DeviceError(_) => {
|
let results = results.into_iter().collect::<Result<Vec<_>, ErrorCode>>();
|
||||||
response::execute::Command::new(execute::Status::Error)
|
|
||||||
}
|
// TODO: We only get one error not all errors
|
||||||
ErrorCode::DeviceException(_) => {
|
if let Err(err) = results {
|
||||||
response::execute::Command::new(execute::Status::Exceptions)
|
(id, Err(err))
|
||||||
}
|
} else {
|
||||||
})
|
(id, Ok(true))
|
||||||
.add_id(&id),
|
}
|
||||||
};
|
} else {
|
||||||
|
(id.clone(), Err(DeviceError::DeviceNotFound.into()))
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut resp_payload = resp_payload.lock().await;
|
let a = join_all(f).await;
|
||||||
resp_payload.add_command(success);
|
a.into_iter().for_each(|(id, state)| {
|
||||||
resp_payload.add_command(offline);
|
match state {
|
||||||
for (error, mut cmd) in errors {
|
Ok(true) => success.add_id(&id),
|
||||||
cmd.error_code = Some(error);
|
Ok(false) => offline.add_id(&id),
|
||||||
resp_payload.add_command(cmd);
|
Err(err) => errors
|
||||||
}
|
.entry(err)
|
||||||
|
.or_insert_with(|| match &err {
|
||||||
|
ErrorCode::DeviceError(_) => {
|
||||||
|
response::execute::Command::new(execute::Status::Error)
|
||||||
|
}
|
||||||
|
ErrorCode::DeviceException(_) => {
|
||||||
|
response::execute::Command::new(execute::Status::Exceptions)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.add_id(&id),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut resp_payload = resp_payload.lock().await;
|
||||||
|
resp_payload.add_command(success);
|
||||||
|
resp_payload.add_command(offline);
|
||||||
|
for (error, mut cmd) in errors {
|
||||||
|
cmd.error_code = Some(error);
|
||||||
|
resp_payload.add_command(cmd);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
154
src/main.rs
154
src/main.rs
@@ -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));
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user