chore+feat(home-assistant): update to pyo3 0.27 and update extraction errors, switch out SmolStr for Arc<str>, tighten up light service calls and implement some for notify, start implementing units of measurement like for power
This commit is contained in:
60
home-assistant/src/notify/service/mobile_app/standard.rs
Normal file
60
home-assistant/src/notify/service/mobile_app/standard.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use mitsein::vec1::Vec1;
|
||||
use pyo3::{types::PyAnyMethods, IntoPyObject, Python};
|
||||
|
||||
use crate::{
|
||||
object_id::ObjectId,
|
||||
service::{service_domain::ServiceDomain, service_id::ServiceId, IntoServiceCall},
|
||||
};
|
||||
|
||||
use super::{
|
||||
Action, NonSpecialMessage, NotifyMobileAppServiceData, NotifyMobileAppServiceDataData,
|
||||
Visibility,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, typed_builder::TypedBuilder)]
|
||||
pub struct StandardNotification {
|
||||
pub object_id: ObjectId,
|
||||
|
||||
#[builder(default, setter(strip_option))]
|
||||
pub title: Option<String>,
|
||||
pub message: NonSpecialMessage,
|
||||
|
||||
#[builder(default, setter(strip_option))]
|
||||
pub actions: Option<Vec1<Action>>,
|
||||
|
||||
#[builder(default, setter(strip_option))]
|
||||
pub visibility: Option<Visibility>,
|
||||
}
|
||||
|
||||
impl IntoServiceCall for StandardNotification {
|
||||
type ServiceData = NotifyMobileAppServiceData;
|
||||
|
||||
fn into_service_call(self) -> (ServiceDomain, ServiceId, Self::ServiceData) {
|
||||
let StandardNotification {
|
||||
object_id,
|
||||
title,
|
||||
message,
|
||||
actions,
|
||||
visibility,
|
||||
} = 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()
|
||||
.title_option(title)
|
||||
.message(message.to_string())
|
||||
.data(
|
||||
NotifyMobileAppServiceDataData::builder()
|
||||
.actions_option(actions.map(Into::into))
|
||||
.visibility_option(visibility)
|
||||
.build(),
|
||||
)
|
||||
.build();
|
||||
|
||||
(service_domain, service_id, service_data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user