Removed old notification system
All checks were successful
Build and deploy / build (push) Successful in 8m50s
Build and deploy / Deploy container (push) Successful in 39s

This commit is contained in:
2025-08-31 00:56:42 +02:00
parent 6c9d2c16c1
commit 03dcd44e0e
4 changed files with 3 additions and 35 deletions

View File

@@ -5,7 +5,7 @@ use dyn_clone::DynClone;
use google_home::traits::OnOff; use google_home::traits::OnOff;
use mlua::ObjectLike; use mlua::ObjectLike;
use crate::event::{OnDarkness, OnMqtt, OnNotification, OnPresence}; use crate::event::{OnDarkness, OnMqtt, OnPresence};
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait LuaDeviceCreate { pub trait LuaDeviceCreate {
@@ -26,7 +26,6 @@ pub trait Device:
+ Cast<dyn OnMqtt> + Cast<dyn OnMqtt>
+ Cast<dyn OnPresence> + Cast<dyn OnPresence>
+ Cast<dyn OnDarkness> + Cast<dyn OnDarkness>
+ Cast<dyn OnNotification>
+ Cast<dyn OnOff> + Cast<dyn OnOff>
{ {
fn get_id(&self) -> String; fn get_id(&self) -> String;

View File

@@ -9,7 +9,7 @@ use tokio_cron_scheduler::{Job, JobScheduler};
use tracing::{debug, instrument, trace}; use tracing::{debug, instrument, trace};
use crate::device::Device; 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<String, Box<dyn Device>>; pub type DeviceMap = HashMap<String, Box<dyn Device>>;
@@ -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; join_all(iter).await;
} }
} }

View File

@@ -3,14 +3,11 @@ use mlua::FromLua;
use rumqttc::Publish; use rumqttc::Publish;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use crate::ntfy::Notification;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Event { pub enum Event {
MqttMessage(Publish), MqttMessage(Publish),
Darkness(bool), Darkness(bool),
Presence(bool), Presence(bool),
Ntfy(Notification),
} }
pub type Sender = mpsc::Sender<Event>; pub type Sender = mpsc::Sender<Event>;
@@ -48,8 +45,3 @@ pub trait OnPresence: Sync + Send {
pub trait OnDarkness: Sync + Send { pub trait OnDarkness: Sync + Send {
async fn on_darkness(&self, dark: bool); async fn on_darkness(&self, dark: bool);
} }
#[async_trait]
pub trait OnNotification: Sync + Send {
async fn on_notification(&self, notification: Notification);
}

View File

@@ -9,7 +9,7 @@ use serde_repr::*;
use tracing::{error, trace, warn}; use tracing::{error, trace, warn};
use crate::device::{Device, LuaDeviceCreate}; use crate::device::{Device, LuaDeviceCreate};
use crate::event::{self, EventChannel, OnNotification}; use crate::event::{self, EventChannel};
use crate::lua::traits::AddAdditionalMethods; use crate::lua::traits::AddAdditionalMethods;
#[derive(Debug, Serialize_repr, Deserialize, Clone, Copy)] #[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 { impl AddAdditionalMethods for Ntfy {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M)
where where