diff --git a/automation_devices/src/lib.rs b/automation_devices/src/lib.rs index 9ad1793..2a60878 100644 --- a/automation_devices/src/lib.rs +++ b/automation_devices/src/lib.rs @@ -74,6 +74,26 @@ macro_rules! impl_device { .unwrap()) }); } + + if impls::impls!($device: google_home::traits::Brightness) { + methods.add_async_method("set_brightness", |_lua, this, brightness: u8| async move { + (this.deref().cast() as Option<&dyn google_home::traits::Brightness>) + .expect("Cast should be valid") + .set_brightness(brightness) + .await + .unwrap(); + + Ok(()) + }); + + methods.add_async_method("brightness", |_lua, this, _: ()| async move { + Ok((this.deref().cast() as Option<&dyn google_home::traits::Brightness>) + .expect("Cast should be valid") + .brightness() + .await + .unwrap()) + }); + } } } }; diff --git a/google_home/google_home/src/traits.rs b/google_home/google_home/src/traits.rs index 73cd517..7137c15 100644 --- a/google_home/google_home/src/traits.rs +++ b/google_home/google_home/src/traits.rs @@ -14,6 +14,11 @@ traits! { async fn on(&self) -> Result, "action.devices.commands.OnOff" => async fn set_on(&self, on: bool) -> Result<(), ErrorCode>, }, + "action.devices.traits.Brightness" => trait Brightness { + command_only_brightness: Option, + async fn brightness(&self) -> Result, + "action.devices.commands.BrightnessAbsolute" => async fn set_brightness(&self, brightness: u8) -> Result<(), ErrorCode>, + }, "action.devices.traits.Scene" => trait Scene { scene_reversible: Option,