diff --git a/README.md b/README.md index 97fc675..2bb63eb 100644 --- a/README.md +++ b/README.md @@ -312,8 +312,6 @@ enable_motion = false # motion detection # (limited battery drain since it # is a passive listening connection) # -enable_pings = false # keep alive pings that keep the camera connected - # enable_light = false # flood lights only avaliable on some camera # (limited battery drain since it # is a passive listening connection) diff --git a/src/config.rs b/src/config.rs index b3c350e..5cf253f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -222,8 +222,6 @@ pub(crate) struct MqttConfig { #[serde(default = "default_true")] pub(crate) enable_motion: bool, #[serde(default = "default_true")] - pub(crate) enable_pings: bool, - #[serde(default = "default_true")] pub(crate) enable_light: bool, #[serde(default = "default_true")] pub(crate) enable_battery: bool, @@ -277,7 +275,6 @@ const fn default_false() -> bool { fn default_mqtt() -> MqttConfig { MqttConfig { - enable_pings: true, enable_motion: true, enable_light: true, enable_battery: true, diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index 5315572..dd0e274 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -403,7 +403,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R Err(Err(e)) => Err(e), }?; AnyResult::Ok(()) - } => v, + }, if config.enable_light => v, // Handle the motion messages v = async { let mut md = camera_motion.motion().await?; @@ -430,7 +430,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R Err(Err(e)) => Err(e), }?; } - } => v, + }, if config.enable_motion => v, // Handle the SNAP (image preview) v = async { let mut wait = IntervalStream::new({ @@ -473,7 +473,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R Err(Err(e)) => Err(e), }?; AnyResult::Ok(()) - } => v, + }, if config.enable_preview => v, // Handle the battery publish v = async { let mut wait = IntervalStream::new({ @@ -517,7 +517,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R Err(Err(e)) => Err(e), }?; AnyResult::Ok(()) - } => v, + }, if config.enable_battery => v, // Handle the push notification messages v = async { let mut pn = camera_pn.push_notifications().await?; diff --git a/src/rtsp/mod.rs b/src/rtsp/mod.rs index 1dcb4c6..41aced3 100644 --- a/src/rtsp/mod.rs +++ b/src/rtsp/mod.rs @@ -67,7 +67,7 @@ use tokio::{ watch::channel as watch, }, task::JoinSet, - time::{interval, sleep, Duration, Instant}, + time::{interval, sleep, Duration}, }; use tokio_stream::wrappers::IntervalStream; use tokio_stream::{wrappers::BroadcastStream, Stream, StreamExt}; @@ -561,7 +561,7 @@ async fn stream_main( v = client_count.aquired_users() => { v?; }, - v = motion.wait_for(|md| matches!(md, crate::common::MdState::Stop(n) if (*n - Instant::now())>delta)) => { + v = motion.wait_for(|md| matches!(md, crate::common::MdState::Stop(n) if n.elapsed()>delta)) => { v?; // Motion has stopped go back continue; @@ -573,7 +573,7 @@ async fn stream_main( v = client_count.dropped_users() => { v?; }, - v = motion.wait_for(|md| matches!(md, crate::common::MdState::Stop(n) if (*n - Instant::now())>delta)) => { + v = motion.wait_for(|md| matches!(md, crate::common::MdState::Stop(n) if n.elapsed()>delta)) => { v?; } } @@ -642,11 +642,17 @@ async fn stream_main( let thread_name = name.clone(); set.spawn(async move { loop { - motion.wait_for(|md| matches!(md, crate::common::MdState::Start(_))).await?; + motion + .wait_for(|md| matches!(md, crate::common::MdState::Start(_))) + .await?; log::info!("{}: Enabling Motion", thread_name); client_activator.activate().await?; - motion.wait_for(|md| matches!(md, crate::common::MdState::Stop(n) if (*n - Instant::now())>delta)).await?; + motion + .wait_for( + |md| matches!(md, crate::common::MdState::Stop(n) if n.elapsed()>delta), + ) + .await?; log::info!("{}: Pausing Motion", thread_name); client_activator.deactivate().await?; }