AudioSetup now takes the name of two already created devices and stores a reference to the devices instead of creating and owning the devices directly

This commit is contained in:
2023-08-14 01:51:45 +02:00
parent 76b75b0cfb
commit e38c5eed31
12 changed files with 151 additions and 77 deletions

View File

@@ -14,7 +14,8 @@ use crate::{
event::{Event, EventChannel, OnMqtt},
};
pub type DeviceMap = HashMap<String, Arc<RwLock<Box<dyn Device>>>>;
pub type WrappedDevice = Arc<RwLock<Box<dyn Device>>>;
pub type DeviceMap = HashMap<String, WrappedDevice>;
#[derive(Debug, Clone)]
pub struct DeviceManager {
@@ -70,6 +71,10 @@ impl DeviceManager {
self.devices.write().await.insert(id, device);
}
pub async fn get(&self, name: &str) -> Option<WrappedDevice> {
self.devices.read().await.get(name).cloned()
}
pub async fn devices(&self) -> RwLockReadGuard<DeviceMap> {
self.devices.read().await
}