feat(entrypoint): trial the power sensor signal for the smart plugs connected to the washer and dryer currently

This commit is contained in:
2026-07-15 02:41:13 -04:00
parent 8d3cde3c43
commit 4eb8a752cc

View File

@@ -2,7 +2,7 @@ use std::{path::PathBuf, str::FromStr, time::Duration};
use clap::Parser; use clap::Parser;
use driver_kasa::connection::LB130USHandle; use driver_kasa::connection::LB130USHandle;
use futures::stream::{FuturesUnordered, StreamExt}; use futures::{TryFutureExt, stream::{FuturesUnordered, StreamExt}};
use home_assistant::{home_assistant::HomeAssistant, object_id::ObjectId}; use home_assistant::{home_assistant::HomeAssistant, object_id::ObjectId};
use protocol::light::{Kelvin, TurnToTemperature}; use protocol::light::{Kelvin, TurnToTemperature};
use pyo3::{ use pyo3::{
@@ -11,7 +11,9 @@ use pyo3::{
wrap_pyfunction, Bound, PyAny, PyResult, Python, wrap_pyfunction, Bound, PyAny, PyResult, Python,
}; };
use shadow_rs::shadow; use shadow_rs::shadow;
use tokio::time::{interval, MissedTickBehavior}; use tokio::{
join, task::JoinSet, time::{MissedTickBehavior, interval}
};
use tracing::{level_filters::LevelFilter, Level}; use tracing::{level_filters::LevelFilter, Level};
use tracing_subscriber::{ use tracing_subscriber::{
fmt::{self, format::FmtSpan}, fmt::{self, format::FmtSpan},
@@ -187,6 +189,58 @@ async fn real_main(
// }, context, target, false).await; // }, context, target, false).await;
// dbg!(total_silence_result); // dbg!(total_silence_result);
// } // }
},
async {
let plug_awp04l_1_power_object_id = "plug_awp04l_1_power";
let plug_awp04l_2_power_object_id = "plug_awp04l_2_power";
let plug_awp04l_1_power_object_id = ObjectId::from_str(plug_awp04l_1_power_object_id)
.expect("statically written and known to be correct");
let plug_awp04l_2_power_object_id = ObjectId::from_str(plug_awp04l_2_power_object_id)
.expect("statically written and known to be correct");
let plug_awp04l_1_power_signal_result = Python::attach(|py| {
home_assistant::sensor::device_classes::power::signal::<f64>(
py,
&home_assistant,
plug_awp04l_1_power_object_id,
)
});
let plug_awp04l_2_power_signal_result = Python::attach(|py| {
home_assistant::sensor::device_classes::power::signal::<f64>(
py,
&home_assistant,
plug_awp04l_2_power_object_id,
)
});
let mut tasks = JoinSet::new();
if let Ok((plug_awp04l_1_power_signal, task)) = plug_awp04l_1_power_signal_result {
tracing::error!("listening to the plug_awp04l_1_power_signal");
tasks.spawn(task.unwrap_or_else(|e| panic!("TODO: {e}")));
tasks.spawn(
plug_awp04l_1_power_signal
.subscribe()
.expect("TODO")
.for_each(|plug_awp04l_1_power| async move {
tracing::warn!(?plug_awp04l_1_power)
}),
);
}
if let Ok((plug_awp04l_2_power_signal, task)) = plug_awp04l_2_power_signal_result {
tracing::error!("listening to the plug_awp04l_2_power_signal");
tasks.spawn(task.unwrap_or_else(|e| panic!("TODO: {e}")));
tasks.spawn(
plug_awp04l_2_power_signal
.subscribe()
.expect("TODO")
.for_each(|plug_awp04l_2_power| async move {
tracing::warn!(?plug_awp04l_2_power)
}),
);
}
tasks.join_all().await;
} }
) )
.0 .0