Device config is now done through lua
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use async_trait::async_trait;
|
||||
use automation_macro::LuaDevice;
|
||||
use google_home::traits::OnOff;
|
||||
use serde::Deserialize;
|
||||
use tracing::{debug, error, trace, warn};
|
||||
@@ -22,7 +23,7 @@ pub struct AudioSetupConfig {
|
||||
#[async_trait]
|
||||
impl DeviceConfig for AudioSetupConfig {
|
||||
async fn create(
|
||||
self,
|
||||
&self,
|
||||
identifier: &str,
|
||||
ext: &ConfigExternal,
|
||||
) -> Result<Box<dyn Device>, DeviceConfigError> {
|
||||
@@ -40,7 +41,10 @@ impl DeviceConfig for AudioSetupConfig {
|
||||
))?;
|
||||
|
||||
if !As::<dyn OnOff>::is(mixer.read().await.as_ref()) {
|
||||
return Err(DeviceConfigError::MissingTrait(self.mixer, "OnOff".into()));
|
||||
return Err(DeviceConfigError::MissingTrait(
|
||||
self.mixer.clone(),
|
||||
"OnOff".into(),
|
||||
));
|
||||
}
|
||||
|
||||
let speakers =
|
||||
@@ -54,14 +58,14 @@ impl DeviceConfig for AudioSetupConfig {
|
||||
|
||||
if !As::<dyn OnOff>::is(speakers.read().await.as_ref()) {
|
||||
return Err(DeviceConfigError::MissingTrait(
|
||||
self.speakers,
|
||||
self.speakers.clone(),
|
||||
"OnOff".into(),
|
||||
));
|
||||
}
|
||||
|
||||
let device = AudioSetup {
|
||||
identifier: identifier.into(),
|
||||
mqtt: self.mqtt,
|
||||
config: self.clone(),
|
||||
mixer,
|
||||
speakers,
|
||||
};
|
||||
@@ -71,10 +75,11 @@ impl DeviceConfig for AudioSetupConfig {
|
||||
}
|
||||
|
||||
// TODO: We need a better way to store the children devices
|
||||
#[derive(Debug)]
|
||||
struct AudioSetup {
|
||||
#[derive(Debug, LuaDevice)]
|
||||
pub struct AudioSetup {
|
||||
identifier: String,
|
||||
mqtt: MqttDeviceConfig,
|
||||
#[config]
|
||||
config: AudioSetupConfig,
|
||||
mixer: WrappedDevice,
|
||||
speakers: WrappedDevice,
|
||||
}
|
||||
@@ -88,7 +93,7 @@ impl Device for AudioSetup {
|
||||
#[async_trait]
|
||||
impl OnMqtt for AudioSetup {
|
||||
fn topics(&self) -> Vec<&str> {
|
||||
vec![&self.mqtt.topic]
|
||||
vec![&self.config.mqtt.topic]
|
||||
}
|
||||
|
||||
async fn on_mqtt(&mut self, message: rumqttc::Publish) {
|
||||
|
||||
Reference in New Issue
Block a user