diff --git a/automation_lib/src/device.rs b/automation_lib/src/device.rs index 0e03ed2..d16c4d4 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::{OnDarkness, OnMqtt, OnNotification, OnPresence}; +use crate::event::{OnDarkness, OnMqtt, OnPresence}; #[async_trait::async_trait] pub trait LuaDeviceCreate { @@ -26,7 +26,6 @@ pub trait Device: + Cast + Cast + 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 329b51c..d84dae3 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, OnDarkness, OnMqtt, OnNotification, OnPresence}; +use crate::event::{Event, EventChannel, OnDarkness, OnMqtt, OnPresence}; pub type DeviceMap = HashMap>; @@ -118,22 +118,6 @@ impl DeviceManager { } }); - join_all(iter).await; - } - Event::Ntfy(notification) => { - let devices = self.devices.read().await; - let iter = devices.iter().map(|(id, device)| { - let notification = notification.clone(); - async move { - let device: Option<&dyn OnNotification> = device.cast(); - if let Some(device) = device { - trace!(id, "Handling"); - device.on_notification(notification).await; - trace!(id, "Done"); - } - } - }); - join_all(iter).await; } } diff --git a/automation_lib/src/event.rs b/automation_lib/src/event.rs index 331793d..7cc7270 100644 --- a/automation_lib/src/event.rs +++ b/automation_lib/src/event.rs @@ -3,14 +3,11 @@ use mlua::FromLua; use rumqttc::Publish; use tokio::sync::mpsc; -use crate::ntfy::Notification; - #[derive(Debug, Clone)] pub enum Event { MqttMessage(Publish), Darkness(bool), Presence(bool), - Ntfy(Notification), } pub type Sender = mpsc::Sender; @@ -48,8 +45,3 @@ pub trait OnPresence: Sync + Send { pub trait OnDarkness: Sync + Send { async fn on_darkness(&self, dark: bool); } - -#[async_trait] -pub trait OnNotification: Sync + Send { - async fn on_notification(&self, notification: Notification); -} diff --git a/automation_lib/src/ntfy.rs b/automation_lib/src/ntfy.rs index 0bdb64b..24006e8 100644 --- a/automation_lib/src/ntfy.rs +++ b/automation_lib/src/ntfy.rs @@ -9,7 +9,7 @@ use serde_repr::*; use tracing::{error, trace, warn}; use crate::device::{Device, LuaDeviceCreate}; -use crate::event::{self, EventChannel, OnNotification}; +use crate::event::{self, EventChannel}; use crate::lua::traits::AddAdditionalMethods; #[derive(Debug, Serialize_repr, Deserialize, Clone, Copy)] @@ -167,13 +167,6 @@ impl Ntfy { } } -#[async_trait] -impl OnNotification for Ntfy { - async fn on_notification(&self, notification: Notification) { - self.send(notification).await; - } -} - impl AddAdditionalMethods for Ntfy { fn add_methods>(methods: &mut M) where