Move front door presence logic to lua
This commit is contained in:
@@ -6,6 +6,7 @@ use automation_lib::action_callback::ActionCallback;
|
||||
use automation_lib::config::MqttDeviceConfig;
|
||||
use automation_lib::device::{Device, LuaDeviceCreate};
|
||||
use automation_lib::event::{self, Event, EventChannel, OnMqtt};
|
||||
use automation_lib::lua::traits::AddAdditionalMethods;
|
||||
use automation_lib::messages::PresenceMessage;
|
||||
use automation_lib::mqtt::WrappedAsyncClient;
|
||||
use automation_macro::{LuaDevice, LuaDeviceConfig};
|
||||
@@ -36,6 +37,7 @@ pub struct State {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, LuaDevice)]
|
||||
#[traits(AddAdditionalMethods)]
|
||||
pub struct Presence {
|
||||
config: Config,
|
||||
state: Arc<RwLock<State>>,
|
||||
@@ -132,3 +134,14 @@ impl OnMqtt for Presence {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAdditionalMethods for Presence {
|
||||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M)
|
||||
where
|
||||
Self: Sized + 'static,
|
||||
{
|
||||
methods.add_async_method("overall_presence", async |_lua, this, ()| {
|
||||
Ok(this.state().await.current_overall_presence)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user