fix: make some types of mobile app notifications work

This commit is contained in:
2026-07-08 16:49:21 -04:00
parent 09d9dcbfe8
commit 9e7e5cdcc8
2 changed files with 65 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
mod do_not_disturb; pub mod do_not_disturb;
mod request_location_update; pub mod request_location_update;
pub use do_not_disturb::DoNotDisturb; pub use do_not_disturb::{DoNotDisturb, Filter as DoNotDisturbFilter};
pub use request_location_update::RequestLocationUpdate; pub use request_location_update::RequestLocationUpdate;

View File

@@ -1,6 +1,6 @@
use std::{convert::Infallible, str::FromStr}; use std::{convert::Infallible, str::FromStr};
use pyo3::{types::PyString, Bound, IntoPyObject, Python}; use pyo3::{types::{PyDict, PyString, PyDictMethods}, Bound, IntoPyObject, Python, PyErr};
use python_utils::IntoPyObjectViaDisplay; use python_utils::IntoPyObjectViaDisplay;
use snafu::Snafu; use snafu::Snafu;
use strum::EnumString; use strum::EnumString;
@@ -215,7 +215,7 @@ impl<'py> IntoPyObject<'py> for MediaStream {
} }
} }
#[derive(Debug, Default, Clone, IntoPyObject, typed_builder::TypedBuilder)] #[derive(Debug, Default, Clone, typed_builder::TypedBuilder)]
#[builder(field_defaults(default, setter(strip_option(fallback_suffix = "_option"))))] #[builder(field_defaults(default, setter(strip_option(fallback_suffix = "_option"))))]
pub struct NotifyMobileAppServiceDataData { pub struct NotifyMobileAppServiceDataData {
actions: Option<Vec<Action>>, actions: Option<Vec<Action>>,
@@ -225,13 +225,72 @@ pub struct NotifyMobileAppServiceDataData {
visibility: Option<Visibility>, visibility: Option<Visibility>,
} }
#[derive(Debug, Clone, IntoPyObject, typed_builder::TypedBuilder)] // TODO: derive macro that does this for me
impl<'py> IntoPyObject<'py> for NotifyMobileAppServiceDataData {
type Target = PyDict;
type Output = Bound<'py, Self::Target>;
type Error = PyErr;
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
let NotifyMobileAppServiceDataData { actions, command, media_stream, tts_text, visibility } = self;
let dict = PyDict::new(py);
if let Some(actions) = actions {
dict.set_item("actions", actions)?;
}
if let Some(command) = command {
dict.set_item("command", command)?;
}
if let Some(media_stream) = media_stream {
dict.set_item("media_stream", media_stream)?;
}
if let Some(tts_text) = tts_text {
dict.set_item("tts_text", tts_text)?;
}
if let Some(visibility) = visibility {
dict.set_item("visibility", visibility)?;
}
Ok(dict)
}
}
#[derive(Debug, Clone, typed_builder::TypedBuilder)]
#[builder(field_defaults(default, setter(strip_option(fallback_suffix = "_option"))))] #[builder(field_defaults(default, setter(strip_option(fallback_suffix = "_option"))))]
pub struct NotifyMobileAppServiceData { pub struct NotifyMobileAppServiceData {
#[builder(!default, setter(!strip_option))] #[builder(!default, setter(!strip_option))]
message: String, message: String,
title: Option<String>, title: Option<String>,
#[builder(setter(!strip_option))] #[builder(setter(!strip_option))]
data: NotifyMobileAppServiceDataData, data: NotifyMobileAppServiceDataData,
} }
// TODO: derive macro that does this for me
impl<'py> IntoPyObject<'py> for NotifyMobileAppServiceData {
type Target = PyDict;
type Output = Bound<'py, Self::Target>;
type Error = PyErr;
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
let NotifyMobileAppServiceData { message, title, data } = self;
let dict = PyDict::new(py);
dict.set_item("message", message)?;
if let Some(title) = title {
dict.set_item("title", title);
}
dict.set_item("data", data);
Ok(dict)
}
}