diff --git a/automation_lib/src/lua/traits.rs b/automation_lib/src/lua/traits.rs index 4e1c724..38c4cb1 100644 --- a/automation_lib/src/lua/traits.rs +++ b/automation_lib/src/lua/traits.rs @@ -2,6 +2,16 @@ use std::ops::Deref; // TODO: Enable and disable functions based on query_only and command_only +pub trait Device { + fn add_methods>(methods: &mut M) + where + Self: Sized + crate::device::Device + 'static, + { + methods.add_async_method("get_id", async |_lua, this, _: ()| Ok(this.get_id())); + } +} +impl Device for T where T: crate::device::Device {} + pub trait OnOff { fn add_methods>(methods: &mut M) where diff --git a/automation_macro/src/device.rs b/automation_macro/src/device.rs index b886436..eec1b9b 100644 --- a/automation_macro/src/device.rs +++ b/automation_macro/src/device.rs @@ -154,13 +154,13 @@ impl quote::ToTokens for Implementation { Ok(b) }); - methods.add_async_method("get_id", async |_lua, this, _: ()| { Ok(this.get_id()) }); + ::automation_lib::lua::traits::Device::add_methods(methods); - #traits + #traits - #( - #add_methods(methods); - )* + #( + #add_methods(methods); + )* } } });