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:
@@ -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)?;
|
||||
|
||||
Reference in New Issue
Block a user