Added OnPresence handler for AudioSetup

This commit is contained in:
Dreaded_X 2023-01-07 05:04:24 +01:00
parent a638de42c1
commit 21b96c2925

View File

@ -1,13 +1,16 @@
use google_home::traits;
use rumqttc::{AsyncClient, matches};
use tracing::{error, warn};
use tracing::{error, warn, debug};
use pollster::FutureExt as _;
use crate::config::MqttDeviceConfig;
use crate::mqtt::{OnMqtt, RemoteMessage, RemoteAction};
use crate::presence::OnPresence;
use super::Device;
// @TODO Ideally we store am Arc to the childern devices,
// that way they hook into everything just like all other devices
pub struct AudioSetup {
identifier: String,
mqtt: MqttDeviceConfig,
@ -67,3 +70,14 @@ impl OnMqtt for AudioSetup {
}
}
}
impl OnPresence for AudioSetup {
fn on_presence(&mut self, presence: bool) {
// Turn off the audio setup when we leave the house
if !presence {
debug!(id = self.identifier, "Turning devices off");
self.speakers.set_on(false).unwrap();
self.mixer.set_on(false).unwrap();
}
}
}