From 34d0266c1f96ff1b795818b9c8abc9cd4044022c Mon Sep 17 00:00:00 2001 From: Jacob Date: Tue, 14 Jul 2026 20:14:45 -0400 Subject: [PATCH] chore: make `MobileAppDeviceId` type instead of using `ObjectId` as that is the wrong abstraction --- .../mobile_app/command/do_not_disturb.rs | 16 +++++++--------- .../command/request_location_update.rs | 14 +++++--------- .../src/notify/service/mobile_app/device_id.rs | 8 ++++++++ .../src/notify/service/mobile_app/mod.rs | 2 ++ .../src/notify/service/mobile_app/standard.rs | 15 ++++++--------- .../notify/service/mobile_app/text_to_speech.rs | 17 ++++++++--------- 6 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 home-assistant/src/notify/service/mobile_app/device_id.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 index 6e9e038..22027ef 100644 --- 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 @@ -1,13 +1,11 @@ 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 crate::service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall}; -use super::super::{NotifyMobileAppServiceData, NotifyMobileAppServiceDataData}; +use super::super::{ + MobileAppDeviceId, NotifyMobileAppServiceData, NotifyMobileAppServiceDataData, SpecialMessage, +}; #[derive(Debug, Clone, EnumString, strum::Display)] #[strum(serialize_all = "snake_case")] @@ -33,7 +31,7 @@ pub enum Filter { #[derive(Debug, Clone, typed_builder::TypedBuilder)] pub struct DoNotDisturb { - pub object_id: ObjectId, + pub device_id: MobileAppDeviceId, pub filter: Filter, } @@ -41,11 +39,11 @@ impl IntoServiceCall for DoNotDisturb { type ServiceData = NotifyMobileAppServiceData; fn into_service_call(self) -> (ServiceDomain, ServiceId, Self::ServiceData) { - let DoNotDisturb { object_id, filter } = self; + let DoNotDisturb { device_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_id = ServiceId::from_str(&format!("mobile_app_{device_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()) diff --git a/home-assistant/src/notify/service/mobile_app/command/request_location_update.rs b/home-assistant/src/notify/service/mobile_app/command/request_location_update.rs index 0da1a4d..e7cd31d 100644 --- a/home-assistant/src/notify/service/mobile_app/command/request_location_update.rs +++ b/home-assistant/src/notify/service/mobile_app/command/request_location_update.rs @@ -1,27 +1,23 @@ use std::str::FromStr; -use crate::{ - notify::service::mobile_app::SpecialMessage, - object_id::ObjectId, - service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall}, -}; +use crate::service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall}; -use super::super::NotifyMobileAppServiceData; +use super::super::{MobileAppDeviceId, NotifyMobileAppServiceData, SpecialMessage}; #[derive(Debug, Clone, typed_builder::TypedBuilder)] pub struct RequestLocationUpdate { - pub object_id: ObjectId, + pub device_id: MobileAppDeviceId, } impl IntoServiceCall for RequestLocationUpdate { type ServiceData = NotifyMobileAppServiceData; fn into_service_call(self) -> (ServiceDomain, ServiceId, Self::ServiceData) { - let RequestLocationUpdate { object_id } = self; + let RequestLocationUpdate { device_id } = 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_id = ServiceId::from_str(&format!("mobile_app_{device_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::RequestLocationUpdate.to_string()) diff --git a/home-assistant/src/notify/service/mobile_app/device_id.rs b/home-assistant/src/notify/service/mobile_app/device_id.rs new file mode 100644 index 0000000..e7700cf --- /dev/null +++ b/home-assistant/src/notify/service/mobile_app/device_id.rs @@ -0,0 +1,8 @@ +use python_utils::{FromPyFromStr, ToStrToPy}; + +use crate::slug::Slug; + +pub use crate::slug::SlugParsingError as ParseMobileAppDeviceIdError; + +#[derive(Debug, Clone, derive_more::FromStr, derive_more::Display, FromPyFromStr, ToStrToPy)] +pub struct MobileAppDeviceId(pub Slug); diff --git a/home-assistant/src/notify/service/mobile_app/mod.rs b/home-assistant/src/notify/service/mobile_app/mod.rs index 94dc753..b25e7b4 100644 --- a/home-assistant/src/notify/service/mobile_app/mod.rs +++ b/home-assistant/src/notify/service/mobile_app/mod.rs @@ -10,10 +10,12 @@ use strum::EnumString; use url::Url; pub mod command; +pub mod device_id; pub mod standard; pub mod text_to_speech; pub use command::*; +pub use device_id::MobileAppDeviceId; pub use standard::StandardNotification; pub use text_to_speech::TextToSpeech; diff --git a/home-assistant/src/notify/service/mobile_app/standard.rs b/home-assistant/src/notify/service/mobile_app/standard.rs index 0d716bd..63edac5 100644 --- a/home-assistant/src/notify/service/mobile_app/standard.rs +++ b/home-assistant/src/notify/service/mobile_app/standard.rs @@ -2,19 +2,16 @@ use std::str::FromStr; use mitsein::vec1::Vec1; -use crate::{ - object_id::ObjectId, - service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall}, -}; +use crate::service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall}; use super::{ - Action, NonSpecialMessage, NotifyMobileAppServiceData, NotifyMobileAppServiceDataData, - Visibility, + Action, MobileAppDeviceId, NonSpecialMessage, NotifyMobileAppServiceData, + NotifyMobileAppServiceDataData, Visibility, }; #[derive(Debug, Clone, typed_builder::TypedBuilder)] pub struct StandardNotification { - pub object_id: ObjectId, + pub device_id: MobileAppDeviceId, #[builder(default, setter(strip_option))] pub title: Option, @@ -32,7 +29,7 @@ impl IntoServiceCall for StandardNotification { fn into_service_call(self) -> (ServiceDomain, ServiceId, Self::ServiceData) { let StandardNotification { - object_id, + device_id, title, message, actions, @@ -41,7 +38,7 @@ impl IntoServiceCall for StandardNotification { 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_id = ServiceId::from_str(&format!("mobile_app_{device_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() .title_option(title) diff --git a/home-assistant/src/notify/service/mobile_app/text_to_speech.rs b/home-assistant/src/notify/service/mobile_app/text_to_speech.rs index b3f4dd2..c4b28b4 100644 --- a/home-assistant/src/notify/service/mobile_app/text_to_speech.rs +++ b/home-assistant/src/notify/service/mobile_app/text_to_speech.rs @@ -1,16 +1,15 @@ use std::str::FromStr; -use crate::{ - notify::service::mobile_app::SpecialMessage, - object_id::ObjectId, - service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall}, -}; +use crate::service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall}; -use super::{MediaStream, NotifyMobileAppServiceData, NotifyMobileAppServiceDataData}; +use super::{ + MediaStream, MobileAppDeviceId, NotifyMobileAppServiceData, NotifyMobileAppServiceDataData, + SpecialMessage, +}; #[derive(Debug, Clone, typed_builder::TypedBuilder)] pub struct TextToSpeech { - pub object_id: ObjectId, + pub device_id: MobileAppDeviceId, pub message: String, pub media_stream: Option, @@ -21,14 +20,14 @@ impl IntoServiceCall for TextToSpeech { fn into_service_call(self) -> (ServiceDomain, ServiceId, Self::ServiceData) { let TextToSpeech { - object_id, + device_id, message, media_stream, } = 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_id = ServiceId::from_str(&format!("mobile_app_{device_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::Tts.to_string())