From 3b7579878b5dc7c3d89aa46e01882e312a155190 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Sun, 19 Oct 2025 02:43:24 +0200 Subject: [PATCH] feat: Use ActionCallback for schedule This has two advantages: - Each schedule entry can take either a single function or table of functions. - We get a better type definition. --- definitions/config.lua | 2 +- src/config.rs | 3 ++- src/schedule.rs | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/definitions/config.lua b/definitions/config.lua index 9892431..c6cc30f 100644 --- a/definitions/config.lua +++ b/definitions/config.lua @@ -10,5 +10,5 @@ local FulfillmentConfig ---@class Config ---@field fulfillment FulfillmentConfig ---@field devices DeviceInterface[]? ----@field schedule table? +---@field schedule table? local Config diff --git a/src/config.rs b/src/config.rs index 2360daf..38d732c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::net::{Ipv4Addr, SocketAddr}; +use automation_lib::action_callback::ActionCallback; use automation_lib::device::Device; use automation_macro::LuaDeviceConfig; use lua_typed::Typed; @@ -39,7 +40,7 @@ pub struct Config { pub devices: Vec>, #[device_config(from_lua, default)] #[typed(default)] - pub schedule: HashMap, + pub schedule: HashMap>, } impl From for SocketAddr { diff --git a/src/schedule.rs b/src/schedule.rs index 62a90ad..543c0fe 100644 --- a/src/schedule.rs +++ b/src/schedule.rs @@ -1,10 +1,11 @@ use std::collections::HashMap; use std::pin::Pin; +use automation_lib::action_callback::ActionCallback; use tokio_cron_scheduler::{Job, JobScheduler, JobSchedulerError}; pub async fn start_scheduler( - schedule: HashMap, + schedule: HashMap>, ) -> Result<(), JobSchedulerError> { let scheduler = JobScheduler::new().await?; @@ -14,7 +15,7 @@ pub async fn start_scheduler( let f = f.clone(); Box::pin(async move { - f.call_async::<()>(()).await.unwrap(); + f.call(()).await; }) } };