Added OnPresence handler for AudioSetup
This commit is contained in:
parent
a638de42c1
commit
21b96c2925
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user