Removed hacky code that got accidentally commited
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3645b53f7c
commit
8cfb346ca5
65
src/main.rs
65
src/main.rs
|
@ -1,5 +1,5 @@
|
|||
#![feature(async_closure)]
|
||||
use std::{collections::HashMap, process, time::Duration};
|
||||
use std::{process, time::Duration};
|
||||
|
||||
use axum::{
|
||||
extract::FromRef, http::StatusCode, response::IntoResponse, routing::post, Json, Router,
|
||||
|
@ -16,8 +16,7 @@ use automation::{
|
|||
};
|
||||
use dotenvy::dotenv;
|
||||
use futures::future::join_all;
|
||||
use rumqttc::{matches, AsyncClient, MqttOptions, Transport};
|
||||
use tokio::task::JoinHandle;
|
||||
use rumqttc::{AsyncClient, MqttOptions, Transport};
|
||||
use tracing::{debug, error, info, metadata::LevelFilter};
|
||||
|
||||
use google_home::{GoogleHome, Request};
|
||||
|
@ -84,11 +83,9 @@ async fn app() -> anyhow::Result<()> {
|
|||
.await?;
|
||||
|
||||
// Start the ntfy service if it is configured
|
||||
let mut ntfy = None;
|
||||
if let Some(config) = &config.ntfy {
|
||||
ntfy = Some(ntfy::start(presence.clone(), config));
|
||||
ntfy::start(presence.clone(), config);
|
||||
}
|
||||
let ntfy = ntfy;
|
||||
|
||||
// Start the hue bridge if it is configured
|
||||
if let Some(config) = &config.hue_bridge {
|
||||
|
@ -105,62 +102,6 @@ async fn app() -> anyhow::Result<()> {
|
|||
);
|
||||
}
|
||||
|
||||
// Super hacky implementation for the washing machine, just for testing
|
||||
{
|
||||
let mut handle = None::<JoinHandle<()>>;
|
||||
let mut mqtt = mqtt.subscribe();
|
||||
client
|
||||
.subscribe("zigbee2mqtt/bathroom/washing", rumqttc::QoS::AtLeastOnce)
|
||||
.await
|
||||
.unwrap();
|
||||
tokio::spawn(async move {
|
||||
if let Some(ntfy) = ntfy {
|
||||
loop {
|
||||
let message = mqtt.recv().await.unwrap();
|
||||
|
||||
if !matches(&message.topic, "zigbee2mqtt/bathroom/washing") {
|
||||
continue;
|
||||
}
|
||||
|
||||
let map: HashMap<String, serde_json::Value> =
|
||||
serde_json::from_slice(&message.payload).unwrap();
|
||||
debug!("Test: {:?}", map);
|
||||
|
||||
let strength = match map.get("strength").map(|value| value.as_i64().unwrap()) {
|
||||
Some(s) => s,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
if strength > 15 {
|
||||
debug!("Strength over 15");
|
||||
|
||||
// Update of strength over 15 which means we are still running, cancel any
|
||||
// running timer
|
||||
if let Some(handle) = handle.take() {
|
||||
handle.abort();
|
||||
}
|
||||
|
||||
// Start a new timer, if the timer runs out we have not had an update of
|
||||
// more then 15 in the last timeout period, assume we are done, notify user
|
||||
let ntfy = ntfy.clone();
|
||||
handle = Some(tokio::spawn(async move {
|
||||
debug!("Starting timeout of 10 min for washing machine...");
|
||||
tokio::time::sleep(Duration::from_secs(10 * 60)).await;
|
||||
debug!("Notifying user!");
|
||||
|
||||
let notification = ntfy::Notification::new()
|
||||
.set_title("Laundy is done")
|
||||
.set_message("Do not forget to hang it!")
|
||||
.set_priority(ntfy::Priority::High);
|
||||
|
||||
ntfy.send(notification).await.ok();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let devices = devices::start(mqtt.subscribe(), presence.clone(), light_sensor.clone());
|
||||
join_all(
|
||||
config
|
||||
|
|
Loading…
Reference in New Issue
Block a user