ActionCallback now always returns self and state can be anything serializable

This commit is contained in:
2024-12-08 02:50:52 +01:00
parent eefb476d7f
commit 41d2af655b
7 changed files with 40 additions and 29 deletions

View File

@@ -32,7 +32,7 @@ pub struct Config {
#[device_config(from_lua, default)]
pub presence: Option<PresenceDeviceConfig>,
#[device_config(from_lua, default)]
pub callback: ActionCallback<bool>,
pub callback: ActionCallback<ContactSensor, bool>,
#[device_config(from_lua)]
pub client: WrappedAsyncClient,
}
@@ -116,7 +116,7 @@ impl OnMqtt for ContactSensor {
return;
}
self.config.callback.call(!is_closed).await;
self.config.callback.call(self, &!is_closed).await;
debug!(id = self.get_id(), "Updating state to {is_closed}");
self.state_mut().await.is_closed = is_closed;