Compare commits
8 Commits
master
...
d71e907c2b
| Author | SHA1 | Date | |
|---|---|---|---|
|
d71e907c2b
|
|||
|
4a120d4d35
|
|||
|
7846649ea4
|
|||
|
297ac9f1ee
|
|||
|
926fdf84c4
|
|||
|
d90eee8a75
|
|||
|
d3f9feb96f
|
|||
|
4a83250258
|
@@ -1,6 +1,12 @@
|
||||
default_install_hook_types:
|
||||
- pre-commit
|
||||
- commit-msg
|
||||
default_stages:
|
||||
- pre-commit
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.6.0
|
||||
rev: v6.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
@@ -11,13 +17,20 @@ repos:
|
||||
- id: check-added-large-files
|
||||
- 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
|
||||
rev: v0.20.0
|
||||
rev: v2.1.0
|
||||
hooks:
|
||||
- id: stylua
|
||||
|
||||
- repo: https://github.com/crate-ci/typos
|
||||
rev: v1.21.0
|
||||
rev: v1.36.1
|
||||
hooks:
|
||||
- id: typos
|
||||
args: ["--force-exclude"]
|
||||
@@ -75,6 +88,6 @@ repos:
|
||||
pass_filenames: false
|
||||
|
||||
- repo: https://github.com/hadolint/hadolint
|
||||
rev: v2.12.0
|
||||
rev: v2.13.1
|
||||
hooks:
|
||||
- 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"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"automation_devices",
|
||||
"automation_lib",
|
||||
"axum",
|
||||
@@ -121,7 +122,6 @@ dependencies = [
|
||||
"async-trait",
|
||||
"automation_lib",
|
||||
"automation_macro",
|
||||
"axum",
|
||||
"bytes",
|
||||
"dyn-clone",
|
||||
"eui48",
|
||||
@@ -172,13 +172,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "axum"
|
||||
version = "0.7.9"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f"
|
||||
checksum = "021e862c184ae977658b36c4500f7feac3221ca5da43e3f25bd04ab6c79a29b5"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum-core",
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
@@ -206,13 +206,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "axum-core"
|
||||
version = "0.4.5"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199"
|
||||
checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"futures-core",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
@@ -237,7 +236,7 @@ dependencies = [
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -254,9 +253,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.3"
|
||||
version = "2.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d"
|
||||
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
|
||||
|
||||
[[package]]
|
||||
name = "bme280"
|
||||
@@ -294,10 +293,11 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.34"
|
||||
version = "1.2.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc"
|
||||
checksum = "590f9024a68a8c40351881787f1934dc11afd69090f5edb6831464694d836ea3"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
@@ -466,7 +466,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -479,6 +479,12 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e178e4fba8a2726903f6ba98a6d221e76f9c12c650d5dc0e6afdc50677b49650"
|
||||
|
||||
[[package]]
|
||||
name = "flume"
|
||||
version = "0.11.1"
|
||||
@@ -617,7 +623,7 @@ dependencies = [
|
||||
"js-sys",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasi 0.14.2+wasi-0.2.4",
|
||||
"wasi 0.14.3+wasi-0.2.4",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
@@ -931,7 +937,7 @@ version = "0.7.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"bitflags 2.9.4",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
]
|
||||
@@ -954,9 +960,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
@@ -1022,9 +1028,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.27"
|
||||
version = "0.4.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
||||
|
||||
[[package]]
|
||||
name = "lru-slab"
|
||||
@@ -1034,18 +1040,18 @@ checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
|
||||
|
||||
[[package]]
|
||||
name = "lua-src"
|
||||
version = "547.0.0"
|
||||
version = "548.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1edaf29e3517b49b8b746701e5648ccb5785cde1c119062cbabbc5d5cd115e42"
|
||||
checksum = "00bc4bd1f1d5c65b30717333cbec4fa7aa378978940a1bca62f404498d423233"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "luajit-src"
|
||||
version = "210.5.12+a4f56a4"
|
||||
version = "210.6.1+f9140a6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3a8e7962a5368d5f264d045a5a255e90f9aa3fc1941ae15a8d2940d42cac671"
|
||||
checksum = "813bd31f2759443affa687c0d9c5eb5cf6cb0e898810ab197408431d746054bf"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"which",
|
||||
@@ -1077,9 +1083,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "matchit"
|
||||
version = "0.7.3"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94"
|
||||
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
|
||||
|
||||
[[package]]
|
||||
name = "maybe-async-cfg"
|
||||
@@ -1128,9 +1134,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mlua"
|
||||
version = "0.10.5"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1f5f8fbebc7db5f671671134b9321c4b9aa9adeafccfd9a8c020ae45c6a35d0"
|
||||
checksum = "5b3dd94c3c4dea0049b22296397040840a8f6b5b5229f438434ba82df402b42d"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"either",
|
||||
@@ -1148,9 +1154,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mlua-sys"
|
||||
version = "0.6.8"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "380c1f7e2099cafcf40e51d3a9f20a346977587aa4d012eae1f043149a728a93"
|
||||
checksum = "3d4dc9cfc5a7698899802e97480617d9726f7da78c910db989d4d0fd4991d900"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cfg-if",
|
||||
@@ -1161,9 +1167,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "mlua_derive"
|
||||
version = "0.10.1"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "870d71c172fcf491c6b5fb4c04160619a2ee3e5a42a1402269c66bcbf1dd4deb"
|
||||
checksum = "465bddde514c4eb3b50b543250e97c1d4b284fa3ef7dc0ba2992c77545dbceb2"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"once_cell",
|
||||
@@ -1176,12 +1182,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
version = "0.50.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
||||
checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399"
|
||||
dependencies = [
|
||||
"overload",
|
||||
"winapi",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1234,12 +1239,6 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.4"
|
||||
@@ -1260,7 +1259,7 @@ dependencies = [
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1289,9 +1288,9 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "potential_utf"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585"
|
||||
checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a"
|
||||
dependencies = [
|
||||
"zerovec",
|
||||
]
|
||||
@@ -1353,7 +1352,7 @@ version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"bitflags 2.9.4",
|
||||
"memchr",
|
||||
"unicase",
|
||||
]
|
||||
@@ -1410,7 +1409,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"socket2",
|
||||
"tracing",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1463,7 +1462,7 @@ version = "0.5.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"bitflags 2.9.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1583,11 +1582,11 @@ version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"bitflags 2.9.4",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1705,7 +1704,7 @@ version = "2.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"bitflags 2.9.4",
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
@@ -1991,9 +1990,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio-cron-scheduler"
|
||||
version = "0.13.0"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a5597b569b4712cf78aa0c9ae29742461b7bda1e49c2a5fdad1d79bf022f8f0"
|
||||
checksum = "5c71ce8f810abc9fabebccc30302a952f9e89c6cf246fafaf170fef164063141"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"croner",
|
||||
@@ -2058,7 +2057,7 @@ version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
"bitflags 2.9.4",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http",
|
||||
@@ -2128,9 +2127,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.19"
|
||||
version = "0.3.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
|
||||
checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5"
|
||||
dependencies = [
|
||||
"nu-ansi-term",
|
||||
"sharded-slab",
|
||||
@@ -2190,9 +2189,9 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.18.0"
|
||||
version = "1.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be"
|
||||
checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2"
|
||||
dependencies = [
|
||||
"getrandom 0.3.3",
|
||||
"js-sys",
|
||||
@@ -2232,11 +2231,11 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||
|
||||
[[package]]
|
||||
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"
|
||||
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||
checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95"
|
||||
dependencies = [
|
||||
"wit-bindgen-rt",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2351,28 +2350,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "windows-core"
|
||||
version = "0.61.2"
|
||||
@@ -2438,7 +2415,7 @@ version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2447,16 +2424,7 @@ version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[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",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2465,31 +2433,14 @@ version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.6",
|
||||
"windows_aarch64_msvc 0.52.6",
|
||||
"windows_i686_gnu 0.52.6",
|
||||
"windows_i686_gnullvm 0.52.6",
|
||||
"windows_i686_msvc 0.52.6",
|
||||
"windows_x86_64_gnu 0.52.6",
|
||||
"windows_x86_64_gnullvm 0.52.6",
|
||||
"windows_x86_64_msvc 0.52.6",
|
||||
]
|
||||
|
||||
[[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",
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2498,96 +2449,48 @@ version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "winsafe"
|
||||
version = "0.0.19"
|
||||
@@ -2595,13 +2498,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rt"
|
||||
version = "0.39.0"
|
||||
name = "wit-bindgen"
|
||||
version = "0.45.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||
dependencies = [
|
||||
"bitflags 2.9.3",
|
||||
]
|
||||
checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814"
|
||||
|
||||
[[package]]
|
||||
name = "writeable"
|
||||
|
||||
110
Cargo.toml
110
Cargo.toml
@@ -5,16 +5,38 @@ edition = "2024"
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"automation_macro",
|
||||
"automation_cast",
|
||||
"google_home/google_home",
|
||||
"google_home/google_home_macro",
|
||||
"automation_devices",
|
||||
"automation_lib",
|
||||
"automation_macro",
|
||||
"google_home/google_home",
|
||||
"google_home/google_home_macro",
|
||||
]
|
||||
|
||||
[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",
|
||||
"vendored",
|
||||
"macros",
|
||||
@@ -22,67 +44,49 @@ mlua = { version = "0.10.1", features = [
|
||||
"async",
|
||||
"send",
|
||||
] }
|
||||
automation_macro = { path = "./automation_macro" }
|
||||
automation_cast = { path = "./automation_cast" }
|
||||
automation_lib = { path = "./automation_lib" }
|
||||
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 = [
|
||||
proc-macro2 = "1.0.101"
|
||||
quote = "1.0.40"
|
||||
reqwest = { version = "0.12.23", features = [
|
||||
"json",
|
||||
"rustls-tls",
|
||||
], default-features = false } # Use rustls, since the other packages also use rustls
|
||||
serde = { version = "1.0.149", features = ["derive"] }
|
||||
serde_json = "1.0.89"
|
||||
serde_repr = "0.1.10"
|
||||
syn = { version = "2.0.60", features = ["extra-traits", "full"] }
|
||||
thiserror = "2.0.5"
|
||||
tokio-cron-scheduler = "0.13.0"
|
||||
tracing-subscriber = "0.3.16"
|
||||
uuid = "1.8.0"
|
||||
rumqttc = "0.24.0"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = "1.0.143"
|
||||
serde_repr = "0.1.20"
|
||||
syn = { version = "2.0.106", features = ["extra-traits", "full"] }
|
||||
thiserror = "2.0.16"
|
||||
tokio = { version = "1", features = ["rt-multi-thread"] }
|
||||
tokio-cron-scheduler = "0.14.0"
|
||||
tracing = "0.1.41"
|
||||
tracing-subscriber = "0.3.20"
|
||||
uuid = "1.18.1"
|
||||
wakey = "0.3.0"
|
||||
air_filter_types = { git = "https://git.huizinga.dev/Dreaded_X/airfilter", tag = "v0.4.4" }
|
||||
|
||||
[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 }
|
||||
async-trait = { workspace = true }
|
||||
automation_devices = { workspace = true }
|
||||
automation_lib = { workspace = true }
|
||||
axum = { workspace = true }
|
||||
dotenvy = { workspace = true }
|
||||
tracing-subscriber = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
google_home = { workspace = true }
|
||||
hostname = { workspace = true }
|
||||
mlua = { 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]
|
||||
wakey = { git = "https://git.huizinga.dev/Dreaded_X/wakey" }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
[package.metadata.typos.default.extend-words]
|
||||
mosquitto = "mosquitto"
|
||||
|
||||
@@ -3,6 +3,4 @@ name = "automation_cast"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -4,23 +4,22 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
air_filter_types = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
async-trait = { workspace = true }
|
||||
automation_lib = { workspace = true }
|
||||
automation_macro = { workspace = true }
|
||||
bytes = { workspace = true }
|
||||
dyn-clone = { workspace = true }
|
||||
eui48 = { workspace = true }
|
||||
google_home = { workspace = true }
|
||||
mlua = { workspace = true }
|
||||
async-trait = { workspace = true }
|
||||
dyn-clone = { workspace = true }
|
||||
reqwest = { workspace = true }
|
||||
rumqttc = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
serde_repr = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
reqwest = { workspace = true } # Use rustls, since the other packages also use rustls
|
||||
anyhow = { workspace = true }
|
||||
axum = { workspace = true }
|
||||
bytes = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
serde_repr = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
eui48 = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
wakey = { workspace = true }
|
||||
air_filter_types = { workspace = true }
|
||||
|
||||
@@ -36,6 +36,9 @@ pub struct Config {
|
||||
|
||||
#[device_config(from_lua, default)]
|
||||
pub callback: ActionCallback<ContactSensor, bool>,
|
||||
#[device_config(from_lua, default)]
|
||||
pub battery_callback: ActionCallback<ContactSensor, f32>,
|
||||
|
||||
#[device_config(from_lua)]
|
||||
pub client: WrappedAsyncClient,
|
||||
}
|
||||
@@ -149,21 +152,27 @@ impl OnMqtt for ContactSensor {
|
||||
return;
|
||||
}
|
||||
|
||||
let is_closed = match ContactMessage::try_from(message) {
|
||||
Ok(state) => state.is_closed(),
|
||||
let message = match ContactMessage::try_from(message) {
|
||||
Ok(message) => message,
|
||||
Err(err) => {
|
||||
error!(id = self.get_id(), "Failed to parse message: {err}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if is_closed == self.state().await.is_closed {
|
||||
return;
|
||||
if let Some(is_closed) = message.contact {
|
||||
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;
|
||||
|
||||
debug!(id = self.get_id(), "Updating state to {is_closed}");
|
||||
self.state_mut().await.is_closed = is_closed;
|
||||
if let Some(battery) = message.battery {
|
||||
self.config.battery_callback.call(self, &battery).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ impl AddAdditionalMethods for HueBridge {
|
||||
{
|
||||
methods.add_async_method(
|
||||
"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)?;
|
||||
|
||||
this.set_flag(flag, value).await;
|
||||
|
||||
@@ -31,9 +31,12 @@ pub struct Config {
|
||||
|
||||
#[device_config(from_lua, default)]
|
||||
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")]
|
||||
enum Action {
|
||||
LeftPress,
|
||||
@@ -48,7 +51,8 @@ enum Action {
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
struct State {
|
||||
action: Action,
|
||||
action: Option<Action>,
|
||||
battery: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, LuaDevice)]
|
||||
@@ -84,32 +88,43 @@ impl OnMqtt for HueSwitch {
|
||||
async fn on_mqtt(&self, message: Publish) {
|
||||
// Check if the message is from the device itself or from a remote
|
||||
if matches(&message.topic, &self.config.mqtt.topic) {
|
||||
let action = match serde_json::from_slice::<State>(&message.payload) {
|
||||
Ok(message) => message.action,
|
||||
let message = match serde_json::from_slice::<State>(&message.payload) {
|
||||
Ok(message) => message,
|
||||
Err(err) => {
|
||||
warn!(id = Device::get_id(self), "Failed to parse message: {err}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
debug!(id = Device::get_id(self), "Remote action = {:?}", action);
|
||||
|
||||
match action {
|
||||
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
|
||||
if let Some(action) = message.action {
|
||||
debug!(
|
||||
id = Device::get_id(self),
|
||||
?message.action,
|
||||
"Action received",
|
||||
);
|
||||
|
||||
match action {
|
||||
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 => {
|
||||
if !self.config.left_hold_callback.is_set() {
|
||||
self.config.left_callback.call(self, &()).await
|
||||
Action::LeftHoldRelease => {
|
||||
if !self.config.left_hold_callback.is_set() {
|
||||
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::config::{InfoConfig, MqttDeviceConfig};
|
||||
use automation_lib::device::{Device, LuaDeviceCreate};
|
||||
@@ -5,7 +6,6 @@ use automation_lib::event::OnMqtt;
|
||||
use automation_lib::messages::{RemoteAction, RemoteMessage};
|
||||
use automation_lib::mqtt::WrappedAsyncClient;
|
||||
use automation_macro::{LuaDevice, LuaDeviceConfig};
|
||||
use axum::async_trait;
|
||||
use rumqttc::{Publish, matches};
|
||||
use tracing::{debug, error, trace};
|
||||
|
||||
@@ -25,6 +25,8 @@ pub struct Config {
|
||||
|
||||
#[device_config(from_lua)]
|
||||
pub callback: ActionCallback<IkeaRemote, bool>,
|
||||
#[device_config(from_lua, default)]
|
||||
pub battery_callback: ActionCallback<IkeaRemote, f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, LuaDevice)]
|
||||
@@ -60,31 +62,38 @@ impl OnMqtt for IkeaRemote {
|
||||
async fn on_mqtt(&self, message: Publish) {
|
||||
// Check if the message is from the deviec itself or from a remote
|
||||
if matches(&message.topic, &self.config.mqtt.topic) {
|
||||
let action = match RemoteMessage::try_from(message) {
|
||||
Ok(message) => message.action(),
|
||||
let message = match RemoteMessage::try_from(message) {
|
||||
Ok(message) => message,
|
||||
Err(err) => {
|
||||
error!(id = Device::get_id(self), "Failed to parse message: {err}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
debug!(id = Device::get_id(self), "Remote action = {:?}", action);
|
||||
|
||||
let on = if self.config.single_button {
|
||||
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(action) = message.action {
|
||||
debug!(id = Device::get_id(self), "Remote action = {:?}", action);
|
||||
|
||||
if let Some(on) = on {
|
||||
self.config.callback.call(self, &on).await;
|
||||
let on = if self.config.single_button {
|
||||
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(
|
||||
"send_notification",
|
||||
|lua, this, notification: mlua::Value| async move {
|
||||
async |lua, this, notification: mlua::Value| {
|
||||
let notification: Notification = lua.from_value(notification)?;
|
||||
|
||||
this.send(notification).await;
|
||||
|
||||
@@ -4,19 +4,19 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
async-trait = { workspace = true }
|
||||
automation_cast = { workspace = true }
|
||||
bytes = { workspace = true }
|
||||
dyn-clone = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
google_home = { workspace = true }
|
||||
indexmap = { workspace = true }
|
||||
mlua = { workspace = true }
|
||||
rumqttc = { workspace = true }
|
||||
serde = { 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 }
|
||||
indexmap = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tokio-cron-scheduler = { workspace = true }
|
||||
mlua = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
uuid = { workspace = true }
|
||||
dyn-clone = { workspace = true }
|
||||
|
||||
@@ -73,22 +73,19 @@ impl DeviceManager {
|
||||
match event {
|
||||
Event::MqttMessage(message) => {
|
||||
let devices = self.devices.read().await;
|
||||
let iter = devices.iter().map(|(id, device)| {
|
||||
let message = message.clone();
|
||||
async move {
|
||||
let device: Option<&dyn OnMqtt> = device.cast();
|
||||
if let Some(device) = device {
|
||||
// let subscribed = device
|
||||
// .topics()
|
||||
// .iter()
|
||||
// .any(|topic| matches(&message.topic, topic));
|
||||
//
|
||||
// if subscribed {
|
||||
trace!(id, "Handling");
|
||||
device.on_mqtt(message).await;
|
||||
trace!(id, "Done");
|
||||
// }
|
||||
}
|
||||
let iter = devices.iter().map(async |(id, device)| {
|
||||
let device: Option<&dyn OnMqtt> = device.cast();
|
||||
if let Some(device) = device {
|
||||
// let subscribed = device
|
||||
// .topics()
|
||||
// .iter()
|
||||
// .any(|topic| matches(&message.topic, topic));
|
||||
//
|
||||
// if subscribed {
|
||||
trace!(id, "Handling");
|
||||
device.on_mqtt(message.clone()).await;
|
||||
trace!(id, "Done");
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
@@ -100,7 +97,7 @@ impl DeviceManager {
|
||||
|
||||
impl mlua::UserData for DeviceManager {
|
||||
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;
|
||||
|
||||
Ok(())
|
||||
@@ -108,7 +105,7 @@ impl mlua::UserData for DeviceManager {
|
||||
|
||||
methods.add_async_method(
|
||||
"schedule",
|
||||
|lua, this, (schedule, f): (String, mlua::Function)| async move {
|
||||
async |lua, this, (schedule, f): (String, mlua::Function)| {
|
||||
debug!("schedule = {schedule}");
|
||||
// This creates a function, that returns the actual job we want to run
|
||||
let create_job = {
|
||||
|
||||
@@ -29,7 +29,7 @@ impl mlua::UserData for Timeout {
|
||||
|
||||
methods.add_async_method(
|
||||
"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() {
|
||||
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");
|
||||
|
||||
if let Some(handle) = this.state.write().await.handle.take() {
|
||||
@@ -60,7 +60,7 @@ impl mlua::UserData for Timeout {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_async_method("is_waiting", |_lua, this, ()| async move {
|
||||
methods.add_async_method("is_waiting", async |_lua, this, ()| {
|
||||
debug!("Canceling timeout callback");
|
||||
|
||||
if let Some(handle) = this.state.read().await.handle.as_ref() {
|
||||
|
||||
@@ -7,13 +7,13 @@ pub trait OnOff {
|
||||
where
|
||||
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();
|
||||
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_async_method("on", |_lua, this, ()| async move {
|
||||
methods.add_async_method("on", async |_lua, this, ()| {
|
||||
Ok(this.deref().on().await.unwrap())
|
||||
});
|
||||
}
|
||||
@@ -25,13 +25,13 @@ pub trait Brightness {
|
||||
where
|
||||
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();
|
||||
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_async_method("brightness", |_lua, this, _: ()| async move {
|
||||
methods.add_async_method("brightness", async |_lua, this, _: ()| {
|
||||
Ok(this.brightness().await.unwrap())
|
||||
});
|
||||
}
|
||||
@@ -45,7 +45,7 @@ pub trait ColorSetting {
|
||||
{
|
||||
methods.add_async_method(
|
||||
"set_color_temperature",
|
||||
|_lua, this, temperature: u32| async move {
|
||||
async |_lua, this, temperature: u32| {
|
||||
this.set_color(google_home::traits::Color { temperature })
|
||||
.await
|
||||
.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)
|
||||
});
|
||||
}
|
||||
@@ -66,16 +66,13 @@ pub trait OpenClose {
|
||||
where
|
||||
Self: Sized + google_home::traits::OpenClose + 'static,
|
||||
{
|
||||
methods.add_async_method(
|
||||
"set_open_percent",
|
||||
|_lua, this, open_percent: u8| async move {
|
||||
this.set_open_percent(open_percent).await.unwrap();
|
||||
methods.add_async_method("set_open_percent", async |_lua, this, open_percent: u8| {
|
||||
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())
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,13 +68,8 @@ pub enum RemoteAction {
|
||||
// Message used to report the action performed by a remote
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct RemoteMessage {
|
||||
action: RemoteAction,
|
||||
}
|
||||
|
||||
impl RemoteMessage {
|
||||
pub fn action(&self) -> RemoteAction {
|
||||
self.action
|
||||
}
|
||||
pub action: Option<RemoteAction>,
|
||||
pub battery: Option<f32>,
|
||||
}
|
||||
|
||||
impl TryFrom<Publish> for RemoteMessage {
|
||||
@@ -144,13 +139,8 @@ impl TryFrom<Publish> for BrightnessMessage {
|
||||
// Message to report the state of a contact sensor
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ContactMessage {
|
||||
contact: bool,
|
||||
}
|
||||
|
||||
impl ContactMessage {
|
||||
pub fn is_closed(&self) -> bool {
|
||||
self.contact
|
||||
}
|
||||
pub contact: Option<bool>,
|
||||
pub battery: Option<f32>,
|
||||
}
|
||||
|
||||
impl TryFrom<Publish> for ContactMessage {
|
||||
|
||||
@@ -27,7 +27,7 @@ impl mlua::UserData for WrappedAsyncClient {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_async_method(
|
||||
"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();
|
||||
|
||||
debug!("message = {message}");
|
||||
|
||||
@@ -45,7 +45,7 @@ impl Impl {
|
||||
quote! {
|
||||
impl mlua::UserData for #name #generics {
|
||||
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)
|
||||
.await
|
||||
.map_err(mlua::ExternalError::into_lua_err)?;
|
||||
@@ -58,7 +58,7 @@ impl Impl {
|
||||
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);
|
||||
|
||||
61
config.lua
61
config.lua
@@ -34,6 +34,37 @@ local ntfy = Ntfy.new({
|
||||
})
|
||||
automation.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
|
||||
automation.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 = {
|
||||
add = function(self, f)
|
||||
self[#self + 1] = f
|
||||
@@ -171,6 +202,7 @@ automation.device_manager:add(HueSwitch.new({
|
||||
right_hold_callback = function()
|
||||
living_lights_relax:set_on(true)
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
|
||||
automation.device_manager:add(WakeOnLAN.new({
|
||||
@@ -222,6 +254,7 @@ automation.device_manager:add(IkeaRemote.new({
|
||||
end
|
||||
end
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
|
||||
local function kettle_timeout()
|
||||
@@ -260,6 +293,7 @@ automation.device_manager:add(IkeaRemote.new({
|
||||
topic = mqtt_z2m("bedroom/remote"),
|
||||
single_button = true,
|
||||
callback = set_kettle,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
|
||||
automation.device_manager:add(IkeaRemote.new({
|
||||
@@ -269,6 +303,7 @@ automation.device_manager:add(IkeaRemote.new({
|
||||
topic = mqtt_z2m("kitchen/remote"),
|
||||
single_button = true,
|
||||
callback = set_kettle,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
|
||||
local function off_timeout(duration)
|
||||
@@ -356,6 +391,7 @@ automation.device_manager:add(IkeaRemote.new({
|
||||
workbench_light:set_on(false)
|
||||
end
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
|
||||
local hallway_top_light = HueGroup.new({
|
||||
@@ -373,6 +409,7 @@ automation.device_manager:add(HueSwitch.new({
|
||||
left_callback = function()
|
||||
hallway_top_light:set_on(not hallway_top_light:on())
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
automation.device_manager:add(HueSwitch.new({
|
||||
name = "SwitchTop",
|
||||
@@ -382,6 +419,7 @@ automation.device_manager:add(HueSwitch.new({
|
||||
left_callback = function()
|
||||
hallway_top_light:set_on(not hallway_top_light:on())
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
|
||||
local hallway_light_automation = {
|
||||
@@ -399,7 +437,7 @@ local hallway_light_automation = {
|
||||
self.group.set_on(true)
|
||||
elseif not self.forced then
|
||||
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)
|
||||
end
|
||||
end)
|
||||
@@ -409,13 +447,21 @@ local hallway_light_automation = {
|
||||
if open then
|
||||
self.group.set_on(true)
|
||||
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)
|
||||
end
|
||||
end
|
||||
end,
|
||||
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
|
||||
self.timeout:cancel()
|
||||
self.forced = true
|
||||
@@ -488,6 +534,7 @@ automation.device_manager:add(IkeaRemote.new({
|
||||
callback = function(_, on)
|
||||
hallway_light_automation:switch_callback(on)
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
local hallway_frontdoor = ContactSensor.new({
|
||||
name = "Frontdoor",
|
||||
@@ -503,6 +550,7 @@ local hallway_frontdoor = ContactSensor.new({
|
||||
hallway_light_automation:door_callback(open)
|
||||
frontdoor_presence(open)
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
})
|
||||
automation.device_manager:add(hallway_frontdoor)
|
||||
hallway_light_automation.door = hallway_frontdoor
|
||||
@@ -516,6 +564,7 @@ local hallway_trash = ContactSensor.new({
|
||||
callback = function(_, open)
|
||||
hallway_light_automation:trash_callback(open)
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
})
|
||||
automation.device_manager:add(hallway_trash)
|
||||
hallway_light_automation.trash = hallway_trash
|
||||
@@ -564,6 +613,7 @@ automation.device_manager:add(HueSwitch.new({
|
||||
left_hold_callback = function()
|
||||
bedroom_lights_relax:set_on(true)
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
|
||||
automation.device_manager:add(ContactSensor.new({
|
||||
@@ -572,24 +622,28 @@ automation.device_manager:add(ContactSensor.new({
|
||||
sensor_type = "Door",
|
||||
topic = mqtt_z2m("living/balcony"),
|
||||
client = mqtt_client,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
automation.device_manager:add(ContactSensor.new({
|
||||
name = "Window",
|
||||
room = "Living Room",
|
||||
topic = mqtt_z2m("living/window"),
|
||||
client = mqtt_client,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
automation.device_manager:add(ContactSensor.new({
|
||||
name = "Window",
|
||||
room = "Bedroom",
|
||||
topic = mqtt_z2m("bedroom/window"),
|
||||
client = mqtt_client,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
automation.device_manager:add(ContactSensor.new({
|
||||
name = "Window",
|
||||
room = "Guest Room",
|
||||
topic = mqtt_z2m("guest/window"),
|
||||
client = mqtt_client,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
|
||||
local storage_light = LightBrightness.new({
|
||||
@@ -614,6 +668,7 @@ automation.device_manager:add(ContactSensor.new({
|
||||
storage_light:set_on(false)
|
||||
end
|
||||
end,
|
||||
battery_callback = check_battery,
|
||||
}))
|
||||
|
||||
automation.device_manager:schedule("0 0 19 * * *", function()
|
||||
|
||||
@@ -3,15 +3,13 @@ name = "google_home"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
async-trait = { workspace = true }
|
||||
automation_cast = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
google_home_macro = { workspace = true }
|
||||
json_value_merge = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
thiserror = { 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 payload: OptionFuture<_> = intent
|
||||
.map(|intent| async move {
|
||||
match intent {
|
||||
Intent::Sync => ResponsePayload::Sync(self.sync(devices).await),
|
||||
Intent::Query(payload) => {
|
||||
ResponsePayload::Query(self.query(payload, devices).await)
|
||||
}
|
||||
Intent::Execute(payload) => {
|
||||
ResponsePayload::Execute(self.execute(payload, devices).await)
|
||||
}
|
||||
.map(async |intent| match intent {
|
||||
Intent::Sync => ResponsePayload::Sync(self.sync(devices).await),
|
||||
Intent::Query(payload) => {
|
||||
ResponsePayload::Query(self.query(payload, devices).await)
|
||||
}
|
||||
Intent::Execute(payload) => {
|
||||
ResponsePayload::Execute(self.execute(payload, devices).await)
|
||||
}
|
||||
})
|
||||
.into();
|
||||
@@ -64,7 +62,7 @@ impl GoogleHome {
|
||||
devices: &HashMap<String, Box<T>>,
|
||||
) -> sync::Payload {
|
||||
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() {
|
||||
Some(Device::sync(device).await)
|
||||
} else {
|
||||
@@ -86,7 +84,7 @@ impl GoogleHome {
|
||||
.devices
|
||||
.into_iter()
|
||||
.map(|device| device.id)
|
||||
.map(|id| async move {
|
||||
.map(async |id| {
|
||||
// NOTE: Requires let_chains feature
|
||||
let device = if let Some(device) = devices.get(id.as_str())
|
||||
&& let Some(device) = device.as_ref().cast()
|
||||
@@ -115,84 +113,77 @@ impl GoogleHome {
|
||||
) -> execute::Payload {
|
||||
let resp_payload = Arc::new(Mutex::new(response::execute::Payload::new()));
|
||||
|
||||
let f = payload.commands.into_iter().map(|command| {
|
||||
let resp_payload = resp_payload.clone();
|
||||
async move {
|
||||
let mut success = response::execute::Command::new(execute::Status::Success);
|
||||
success.states = Some(execute::States {
|
||||
online: true,
|
||||
state: Default::default(),
|
||||
});
|
||||
let mut offline = response::execute::Command::new(execute::Status::Offline);
|
||||
offline.states = Some(execute::States {
|
||||
online: false,
|
||||
state: Default::default(),
|
||||
});
|
||||
let mut errors: HashMap<ErrorCode, response::execute::Command> = HashMap::new();
|
||||
let f = payload.commands.into_iter().map(async |command| {
|
||||
let mut success = response::execute::Command::new(execute::Status::Success);
|
||||
success.states = Some(execute::States {
|
||||
online: true,
|
||||
state: Default::default(),
|
||||
});
|
||||
let mut offline = response::execute::Command::new(execute::Status::Offline);
|
||||
offline.states = Some(execute::States {
|
||||
online: false,
|
||||
state: Default::default(),
|
||||
});
|
||||
let mut errors: HashMap<ErrorCode, response::execute::Command> = HashMap::new();
|
||||
|
||||
let f = command
|
||||
.devices
|
||||
.into_iter()
|
||||
.map(|device| device.id)
|
||||
.map(|id| {
|
||||
let execution = command.execution.clone();
|
||||
async move {
|
||||
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));
|
||||
}
|
||||
|
||||
// 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 f = command
|
||||
.devices
|
||||
.into_iter()
|
||||
.map(|device| device.id)
|
||||
.map(async |id| {
|
||||
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));
|
||||
}
|
||||
});
|
||||
|
||||
let a = join_all(f).await;
|
||||
a.into_iter().for_each(|(id, state)| {
|
||||
match state {
|
||||
Ok(true) => success.add_id(&id),
|
||||
Ok(false) => offline.add_id(&id),
|
||||
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),
|
||||
};
|
||||
// NOTE: We can not use .map here because async =(
|
||||
let mut results = Vec::new();
|
||||
for cmd in &command.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 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);
|
||||
}
|
||||
let a = join_all(f).await;
|
||||
a.into_iter().for_each(|(id, state)| {
|
||||
match state {
|
||||
Ok(true) => success.add_id(&id),
|
||||
Ok(false) => offline.add_id(&id),
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
15
src/main.rs
15
src/main.rs
@@ -97,9 +97,18 @@ async fn app() -> anyhow::Result<()> {
|
||||
.collect();
|
||||
|
||||
// Level 1 of the stack gives us the location that called this function
|
||||
let stack = lua.inspect_stack(1).unwrap();
|
||||
let file = stack.source().short_src.unwrap_or("?".into());
|
||||
let line = stack.curr_line();
|
||||
let (file, line) = lua
|
||||
.inspect_stack(1, |debug| {
|
||||
(
|
||||
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
|
||||
// config
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::result;
|
||||
|
||||
use axum::async_trait;
|
||||
use axum::extract::{FromRef, FromRequestParts};
|
||||
use axum::http::StatusCode;
|
||||
use axum::http::request::Parts;
|
||||
@@ -79,7 +78,6 @@ pub struct User {
|
||||
pub preferred_username: String,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for User
|
||||
where
|
||||
String: FromRef<S>,
|
||||
@@ -116,7 +114,7 @@ where
|
||||
.await
|
||||
.map_err(|err| ApiError::new(StatusCode::INTERNAL_SERVER_ERROR, err.into()))?;
|
||||
|
||||
return Ok(user);
|
||||
Ok(user)
|
||||
} else {
|
||||
let err: ApiErrorJson = res
|
||||
.json()
|
||||
|
||||
Reference in New Issue
Block a user