Compare commits
2 Commits
09d9dcbfe8
...
89404a56e0
| Author | SHA1 | Date | |
|---|---|---|---|
| 89404a56e0 | |||
| 9e7e5cdcc8 |
@@ -101,6 +101,8 @@ async fn real_main(
|
|||||||
let built_at = build_info::BUILD_TIME;
|
let built_at = build_info::BUILD_TIME;
|
||||||
tracing::info!(built_at);
|
tracing::info!(built_at);
|
||||||
|
|
||||||
|
tokio::join!(
|
||||||
|
async {
|
||||||
let mut bathroom_mirror_lights = [
|
let mut bathroom_mirror_lights = [
|
||||||
LB130USHandle::new(
|
LB130USHandle::new(
|
||||||
([10, 0, 3, 80], 9999).into(),
|
([10, 0, 3, 80], 9999).into(),
|
||||||
@@ -126,16 +128,71 @@ async fn real_main(
|
|||||||
|
|
||||||
let tasks = bathroom_mirror_lights
|
let tasks = bathroom_mirror_lights
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.map(|bathroom_mirror_light| bathroom_mirror_light.turn_to_temperature(temperature));
|
.map(|bathroom_mirror_light| {
|
||||||
|
bathroom_mirror_light.turn_to_temperature(temperature)
|
||||||
|
});
|
||||||
let mut tasks = FuturesUnordered::from_iter(tasks);
|
let mut tasks = FuturesUnordered::from_iter(tasks);
|
||||||
|
|
||||||
while let Some(result) = tasks.next().await {
|
while let Some(result) = tasks.next().await {
|
||||||
match result {
|
match result {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(error_turning_to_temperature) => tracing::error!(?error_turning_to_temperature),
|
Err(error_turning_to_temperature) => {
|
||||||
|
tracing::error!(?error_turning_to_temperature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async {
|
||||||
|
let jacob_phone_id = "galaxy_s21_ultra_1";
|
||||||
|
let jacob_phone_object_id = ObjectId::from_str(jacob_phone_id).unwrap();
|
||||||
|
|
||||||
|
let services = Python::attach(|py| home_assistant.services(py)).unwrap();
|
||||||
|
|
||||||
|
let mut interval = interval(Duration::from_secs(15));
|
||||||
|
interval.set_missed_tick_behavior(MissedTickBehavior::Delay);
|
||||||
|
|
||||||
|
use home_assistant::notify::service::mobile_app::command;
|
||||||
|
|
||||||
|
// loop {
|
||||||
|
// let instant = interval.tick().await;
|
||||||
|
// let context: Option<Context<()>> = None;
|
||||||
|
// let target: Option<()> = None;
|
||||||
|
// let turn_off_result: Result<Py<PyAny>, _> = services.call_service(command::DoNotDisturb {
|
||||||
|
// object_id: jacob_phone_object_id.clone(),
|
||||||
|
// filter: command::DoNotDisturbFilter::Off,
|
||||||
|
// }, context, target, false).await;
|
||||||
|
// dbg!(turn_off_result);
|
||||||
|
|
||||||
|
// let instant = interval.tick().await;
|
||||||
|
// let context: Option<Context<()>> = None;
|
||||||
|
// let target: Option<()> = None;
|
||||||
|
// let alarms_only_result: Result<Py<PyAny>, _> = services.call_service(command::DoNotDisturb {
|
||||||
|
// object_id: jacob_phone_object_id.clone(),
|
||||||
|
// filter: command::DoNotDisturbFilter::AlarmsOnly,
|
||||||
|
// }, context, target, false).await;
|
||||||
|
// dbg!(alarms_only_result);
|
||||||
|
|
||||||
|
// let instant = interval.tick().await;
|
||||||
|
// let context: Option<Context<()>> = None;
|
||||||
|
// let target: Option<()> = None;
|
||||||
|
// let priority_only_result: Result<Py<PyAny>, _> = services.call_service(command::DoNotDisturb {
|
||||||
|
// object_id: jacob_phone_object_id.clone(),
|
||||||
|
// filter: command::DoNotDisturbFilter::PriorityOnly,
|
||||||
|
// }, context, target, false).await;
|
||||||
|
// dbg!(priority_only_result);
|
||||||
|
|
||||||
|
// let instant = interval.tick().await;
|
||||||
|
// let context: Option<Context<()>> = None;
|
||||||
|
// let target: Option<()> = None;
|
||||||
|
// let total_silence_result: Result<Py<PyAny>, _> = services.call_service(command::DoNotDisturb {
|
||||||
|
// object_id: jacob_phone_object_id.clone(),
|
||||||
|
// filter: command::DoNotDisturbFilter::TotalSilence,
|
||||||
|
// }, context, target, false).await;
|
||||||
|
// dbg!(total_silence_result);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
).0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user