Handle turning off devices when away through lua
This commit is contained in:
@@ -7,7 +7,7 @@ use async_trait::async_trait;
|
||||
use automation_lib::action_callback::ActionCallback;
|
||||
use automation_lib::config::{InfoConfig, MqttDeviceConfig};
|
||||
use automation_lib::device::{Device, LuaDeviceCreate};
|
||||
use automation_lib::event::{OnMqtt, OnPresence};
|
||||
use automation_lib::event::OnMqtt;
|
||||
use automation_lib::helpers::serialization::state_deserializer;
|
||||
use automation_lib::mqtt::WrappedAsyncClient;
|
||||
use automation_macro::{LuaDevice, LuaDeviceConfig};
|
||||
@@ -50,10 +50,6 @@ pub struct Config<T: OutletState> {
|
||||
#[device_config(default(OutletType::Outlet))]
|
||||
pub outlet_type: OutletType,
|
||||
|
||||
// TODO: One presence is reworked, this should be removed!
|
||||
#[device_config(default(true))]
|
||||
pub presence_auto_off: bool,
|
||||
|
||||
#[device_config(from_lua, default)]
|
||||
pub callback: ActionCallback<Outlet<T>, T>,
|
||||
|
||||
@@ -202,16 +198,6 @@ impl OnMqtt for Outlet<StatePower> {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: OutletState> OnPresence for Outlet<T> {
|
||||
async fn on_presence(&self, presence: bool) {
|
||||
if self.config.presence_auto_off && !presence {
|
||||
debug!(id = Device::get_id(self), "Turning device off");
|
||||
self.set_on(false).await.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T: OutletState> google_home::Device for Outlet<T> {
|
||||
fn get_device_type(&self) -> Type {
|
||||
|
||||
Reference in New Issue
Block a user