Reorganized project

This commit is contained in:
2024-12-08 00:15:03 +01:00
parent 42f391cde6
commit 8877b24e84
36 changed files with 505 additions and 797 deletions

View File

@@ -0,0 +1,55 @@
use async_trait::async_trait;
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<Event>;
pub type Receiver = mpsc::Receiver<Event>;
#[derive(Clone, Debug, FromLua)]
pub struct EventChannel(Sender);
impl EventChannel {
pub fn new() -> (Self, Receiver) {
let (tx, rx) = mpsc::channel(100);
(Self(tx), rx)
}
pub fn get_tx(&self) -> Sender {
self.0.clone()
}
}
impl mlua::UserData for EventChannel {}
#[async_trait]
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);
}
#[async_trait]
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);
}