diff --git a/src/action_callback.rs b/src/action_callback.rs index d6c9a78..fe21dbb 100644 --- a/src/action_callback.rs +++ b/src/action_callback.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use mlua::{FromLua, IntoLua}; +use mlua::{FromLua, IntoLuaMulti}; #[derive(Debug, Clone)] struct Internal { @@ -8,12 +8,21 @@ struct Internal { lua: mlua::Lua, } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone)] pub struct ActionCallback { internal: Option, phantom: PhantomData, } +impl Default for ActionCallback { + fn default() -> Self { + Self { + internal: None, + phantom: PhantomData::, + } + } +} + impl FromLua for ActionCallback { fn from_lua(value: mlua::Value, lua: &mlua::Lua) -> mlua::Result { let uuid = uuid::Uuid::new_v4(); @@ -32,7 +41,7 @@ impl FromLua for ActionCallback { // TODO: Return proper error here impl ActionCallback where - T: IntoLua + Sync + Send + Clone + Copy + 'static, + T: IntoLuaMulti + Sync + Send + Clone + 'static, { pub async fn call(&self, state: T) { let Some(internal) = self.internal.as_ref() else { diff --git a/src/devices/hue_switch.rs b/src/devices/hue_switch.rs index 97fbd43..b9f388a 100644 --- a/src/devices/hue_switch.rs +++ b/src/devices/hue_switch.rs @@ -22,12 +22,11 @@ pub struct Config { #[device_config(from_lua)] pub client: WrappedAsyncClient, - // TODO: IntoLua is not implemented for unit type () #[device_config(from_lua, default)] - pub left_callback: ActionCallback, + pub left_callback: ActionCallback<()>, #[device_config(from_lua, default)] - pub right_callback: ActionCallback, + pub right_callback: ActionCallback<()>, } #[derive(Debug, Clone)] @@ -75,10 +74,10 @@ impl OnMqtt for HueSwitch { match action { zigbee2mqtt_types::vendors::philips::Zigbee929003017102Action::Leftpress => { - self.config.left_callback.call(true).await + self.config.left_callback.call(()).await } zigbee2mqtt_types::vendors::philips::Zigbee929003017102Action::Rightpress => { - self.config.right_callback.call(true).await + self.config.right_callback.call(()).await } _ => {} }