diff --git a/src/config.rs b/src/config.rs index eb8793e..c9820b0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,6 @@ use std::collections::{HashMap, VecDeque}; use std::net::{Ipv4Addr, SocketAddr}; +use std::ops::Deref; use automation_lib::action_callback::ActionCallback; use automation_lib::device::Device; @@ -60,6 +61,14 @@ impl FromLua for SetupFunction { } } +impl Deref for SetupFunction { + type Target = mlua::Function; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + #[derive(Debug, Default)] pub struct Schedule(HashMap>); @@ -83,6 +92,16 @@ impl FromLua for Schedule { } } +impl IntoIterator for Schedule { + type Item = > as IntoIterator>::Item; + + type IntoIter = > as IntoIterator>::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + #[derive(Debug, Default)] pub struct Module { pub setup: Option, @@ -189,7 +208,7 @@ impl Modules { modules.extend(module.modules); if let Some(setup) = module.setup { - let result: mlua::Value = setup.0.call_async(client.clone()).await?; + let result: mlua::Value = setup.call_async(client.clone()).await?; if result.is_nil() { // We ignore nil results @@ -209,7 +228,7 @@ impl Modules { } devices.extend(module.devices); - for (cron, f) in module.schedule.0 { + for (cron, f) in module.schedule { scheduler.add_job(cron, f); } }