Compare commits

...

2 Commits

7 changed files with 36 additions and 39 deletions

View File

@@ -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())

View File

@@ -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())

View File

@@ -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);

View File

@@ -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;

View File

@@ -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<String>,
@@ -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)

View File

@@ -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<MediaStream>,
@@ -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())

View File

@@ -1,6 +1,3 @@
use std::convert::Infallible;
use pyo3::{prelude::*, types::PyString};
use python_utils::{FromPyFromStr, ToStrToPy};
use super::slug::Slug;