Removed old presence system
This commit is contained in:
@@ -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<dyn google_home::Device>
|
||||
+ Cast<dyn OnMqtt>
|
||||
+ Cast<dyn OnPresence>
|
||||
+ Cast<dyn OnOff>
|
||||
Debug + DynClone + Sync + Send + Cast<dyn google_home::Device> + Cast<dyn OnMqtt> + Cast<dyn OnOff>
|
||||
{
|
||||
fn get_id(&self) -> String;
|
||||
}
|
||||
|
||||
@@ -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<String, Box<dyn Device>>;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use tokio::sync::mpsc;
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Event {
|
||||
MqttMessage(Publish),
|
||||
Presence(bool),
|
||||
}
|
||||
|
||||
pub type Sender = mpsc::Sender<Event>;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user