refactor!: Rewrote device implementation macro once again

This time with a bit more though put into the design of the code, as a
result the macro should be a lot more robust.

This did result in the macro getting renamed from LuaDevice to Device as
this should be _the_ Device macro.
The attribute also got renamed from traits() to device(traits()) and the
syntax got overhauled to allow for a bit more expression.
This commit is contained in:
2025-09-09 02:48:44 +02:00
parent aad089aa10
commit ff78ac0c76
19 changed files with 274 additions and 140 deletions

View File

@@ -7,7 +7,7 @@ mod web;
use std::net::SocketAddr;
use std::path::Path;
use std::process;
use std::time::{SystemTime, UNIX_EPOCH};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use ::config::{Environment, File};
use automation_lib::config::{FulfillmentConfig, MqttConfig};
@@ -172,6 +172,11 @@ async fn app() -> anyhow::Result<()> {
.as_millis())
})?;
utils.set("get_epoch", get_epoch)?;
let sleep = lua.create_async_function(async |_lua, duration: u64| {
tokio::time::sleep(Duration::from_millis(duration)).await;
Ok(())
})?;
utils.set("sleep", sleep)?;
lua.register_module("utils", utils)?;
automation_devices::register_with_lua(&lua)?;