diff --git a/automation_devices/src/presence.rs b/automation_devices/src/presence.rs index b637d13..8d6bd48 100644 --- a/automation_devices/src/presence.rs +++ b/automation_devices/src/presence.rs @@ -5,7 +5,7 @@ use async_trait::async_trait; 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::event::OnMqtt; use automation_lib::lua::traits::AddAdditionalMethods; use automation_lib::messages::PresenceMessage; use automation_lib::mqtt::WrappedAsyncClient; @@ -18,8 +18,6 @@ use tracing::{debug, trace, warn}; pub struct Config { #[device_config(flatten)] pub mqtt: MqttDeviceConfig, - #[device_config(from_lua, rename("event_channel"), with(|ec: EventChannel| ec.get_tx()))] - pub tx: event::Sender, #[device_config(from_lua, default)] pub callback: ActionCallback, @@ -120,16 +118,6 @@ impl OnMqtt for Presence { debug!("Overall presence updated: {overall_presence}"); self.state_mut().await.current_overall_presence = overall_presence; - if self - .config - .tx - .send(Event::Presence(overall_presence)) - .await - .is_err() - { - warn!("There are no receivers on the event channel"); - } - self.config.callback.call(self, &overall_presence).await; } } diff --git a/automation_lib/src/device.rs b/automation_lib/src/device.rs index 2b4b859..ebfffbb 100644 --- a/automation_lib/src/device.rs +++ b/automation_lib/src/device.rs @@ -5,7 +5,7 @@ use dyn_clone::DynClone; use google_home::traits::OnOff; use mlua::ObjectLike; -use crate::event::{OnMqtt, OnPresence}; +use crate::event::OnMqtt; #[async_trait::async_trait] pub trait LuaDeviceCreate { @@ -18,14 +18,7 @@ pub trait LuaDeviceCreate { } pub trait Device: - Debug - + DynClone - + Sync - + Send - + Cast - + Cast - + Cast - + Cast + Debug + DynClone + Sync + Send + Cast + Cast + Cast { fn get_id(&self) -> String; } diff --git a/automation_lib/src/device_manager.rs b/automation_lib/src/device_manager.rs index 96b1cc3..bbad8a6 100644 --- a/automation_lib/src/device_manager.rs +++ b/automation_lib/src/device_manager.rs @@ -9,7 +9,7 @@ use tokio_cron_scheduler::{Job, JobScheduler}; use tracing::{debug, instrument, trace}; use crate::device::Device; -use crate::event::{Event, EventChannel, OnMqtt, OnPresence}; +use crate::event::{Event, EventChannel, OnMqtt}; pub type DeviceMap = HashMap>; @@ -92,19 +92,6 @@ impl DeviceManager { } }); - join_all(iter).await; - } - Event::Presence(presence) => { - let devices = self.devices.read().await; - let iter = devices.iter().map(|(id, device)| async move { - let device: Option<&dyn OnPresence> = device.cast(); - if let Some(device) = device { - trace!(id, "Handling"); - device.on_presence(presence).await; - trace!(id, "Done"); - } - }); - join_all(iter).await; } } diff --git a/automation_lib/src/event.rs b/automation_lib/src/event.rs index 9062699..85ababb 100644 --- a/automation_lib/src/event.rs +++ b/automation_lib/src/event.rs @@ -6,7 +6,6 @@ use tokio::sync::mpsc; #[derive(Debug, Clone)] pub enum Event { MqttMessage(Publish), - Presence(bool), } pub type Sender = mpsc::Sender; @@ -34,8 +33,3 @@ pub trait OnMqtt: Sync + Send { // fn topics(&self) -> Vec<&str>; async fn on_mqtt(&self, message: Publish); } - -#[async_trait] -pub trait OnPresence: Sync + Send { - async fn on_presence(&self, presence: bool); -} diff --git a/config.lua b/config.lua index 6b404ef..56917a0 100644 --- a/config.lua +++ b/config.lua @@ -43,7 +43,6 @@ local on_presence = { local presence_system = Presence.new({ topic = mqtt_automation("presence/+/#"), client = mqtt_client, - event_channel = automation.device_manager:event_channel(), callback = function(_, presence) for _, f in ipairs(on_presence) do if type(f) == "function" then