Fix some stary bugs in md pause and enable_preview

This commit is contained in:
QuantumEntangledAndy committed 2023-09-27 15:40:38 +07:00
1 parent 6bea9a805e
commit a8cee8d294
4 files changed
+15 -14

No files matched your search

-2
View File
@@ -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)
-3
View File
@@ -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,
+4 -4
View File
@@ -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?;
+11 -5
View File
@@ -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?;
}