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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user