From 09d9dcbfe81b4e69cc48a04266fce8f6974fd506 Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 8 Jul 2026 14:38:17 -0400 Subject: [PATCH] feat: command do not disturb --- .../mobile_app/command/do_not_disturb.rs | 61 +++++++++++++++++++ .../notify/service/mobile_app/command/mod.rs | 2 + .../src/notify/service/mobile_app/mod.rs | 1 + 3 files changed, 64 insertions(+) create mode 100644 home-assistant/src/notify/service/mobile_app/command/do_not_disturb.rs diff --git a/home-assistant/src/notify/service/mobile_app/command/do_not_disturb.rs b/home-assistant/src/notify/service/mobile_app/command/do_not_disturb.rs new file mode 100644 index 0000000..6e9e038 --- /dev/null +++ b/home-assistant/src/notify/service/mobile_app/command/do_not_disturb.rs @@ -0,0 +1,61 @@ +use std::str::FromStr; +use strum::EnumString; + +use crate::{ + notify::service::mobile_app::SpecialMessage, + object_id::ObjectId, + service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall}, +}; + +use super::super::{NotifyMobileAppServiceData, NotifyMobileAppServiceDataData}; + +#[derive(Debug, Clone, EnumString, strum::Display)] +#[strum(serialize_all = "snake_case")] +pub enum Filter { + /// Normal interruption filter - + /// no notifications are suppressed + Off, + + /// Alarms only interruption filter - + /// all notifications except those in the alarm category are suppressed. + /// Some audio streams are muted + AlarmsOnly, + + /// Priority interruption filter - + /// all notifications are suppressed except those that match the priority criteria. + /// Some audio streams are muted + PriorityOnly, + + /// No interruptions filter - + /// all notifications are suppressed and all audio streams (except those used for phone calls) and vibrations are muted + TotalSilence, +} + +#[derive(Debug, Clone, typed_builder::TypedBuilder)] +pub struct DoNotDisturb { + pub object_id: ObjectId, + pub filter: Filter, +} + +impl IntoServiceCall for DoNotDisturb { + type ServiceData = NotifyMobileAppServiceData; + + fn into_service_call(self) -> (ServiceDomain, ServiceId, Self::ServiceData) { + let DoNotDisturb { object_id, filter } = self; + + let service_domain = ServiceDomain::from_str("notify").expect("statically written and known to be a valid slug; hoping to get compiler checks instead in the future"); + + let service_id = ServiceId::from_str(&format!("mobile_app_{object_id}")).expect("statically written and known to be a valid slug; hoping to get compiler checks instead in the future"); + + let service_data = NotifyMobileAppServiceData::builder() + .message(SpecialMessage::CommandDnd.to_string()) + .data( + NotifyMobileAppServiceDataData::builder() + .command(filter.to_string()) + .build(), + ) + .build(); + + (service_domain, service_id, service_data) + } +} diff --git a/home-assistant/src/notify/service/mobile_app/command/mod.rs b/home-assistant/src/notify/service/mobile_app/command/mod.rs index d65fe8a..fdde121 100644 --- a/home-assistant/src/notify/service/mobile_app/command/mod.rs +++ b/home-assistant/src/notify/service/mobile_app/command/mod.rs @@ -1,3 +1,5 @@ +mod do_not_disturb; mod request_location_update; +pub use do_not_disturb::DoNotDisturb; pub use request_location_update::RequestLocationUpdate; diff --git a/home-assistant/src/notify/service/mobile_app/mod.rs b/home-assistant/src/notify/service/mobile_app/mod.rs index d5da68d..8d9fe36 100644 --- a/home-assistant/src/notify/service/mobile_app/mod.rs +++ b/home-assistant/src/notify/service/mobile_app/mod.rs @@ -219,6 +219,7 @@ impl<'py> IntoPyObject<'py> for MediaStream { #[builder(field_defaults(default, setter(strip_option(fallback_suffix = "_option"))))] pub struct NotifyMobileAppServiceDataData { actions: Option>, + command: Option, media_stream: Option, tts_text: Option, visibility: Option,