Skip to content

Commit

Permalink
Wait for a change before sending a visitor in the queue
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumEntangledAndy committed Jan 25, 2025
1 parent 8d1b8e0 commit 474aaea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/core/src/bc_protocol/motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ impl MotionData {
return Ok(());
}
Some(Ok(Some(_))) => {
// conitnue to next data
// continue to next data
}
Some(Err(e)) => return Err(e),
None => {
// Timoout occured motion stopped
// Timeout occured motion stopped
return Ok(());
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/mqtt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,14 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
let mut vis = camera_visitor.visitor().await?;
loop {
let v = async {
vis.changed().await.with_context(|| {
format!("{}: ViaStart Watch Dropped", camera_name)
})?;
vis.wait_for(|state| matches!(state, VisitorState::Visted(_))).await.with_context(|| {
format!("{}: MdStart Watch Dropped", camera_name)
format!("{}: ViaStart Watch Dropped", camera_name)
})?;
mqtt_visitor.send_message("status/visitor", "visitor", true).await.with_context(|| {
format!("{}: Failed to publish motion start", camera_name)
format!("{}: Failed to publish visitor", camera_name)
})?;
AnyResult::Ok(())
}.await;
Expand All @@ -509,8 +512,11 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
loop {
let v = async {
let ai_kind = {
ai.changed().await.with_context(|| {
format!("{}: AiStart Watch Dropped", camera_name)
})?;
let ai_state = ai.wait_for(|state| !matches!(state, AiState::Unknown)).await.with_context(|| {
format!("{}: MdStart Watch Dropped", camera_name)
format!("{}: AiStart Watch Dropped", camera_name)
})?;
match &*ai_state {
AiState::Person(_) => "person",
Expand All @@ -521,10 +527,10 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
};

mqtt_ai.send_message("status/ai", ai_kind, true).await.with_context(|| {
format!("{}: Failed to publish motion start", camera_name)
format!("{}: Failed to publish ai msg", camera_name)
})?;
mqtt_ai.send_message(&format!("status/ai/{}", ai_kind), ai_kind, true).await.with_context(|| {
format!("{}: Failed to publish motion start", camera_name)
format!("{}: Failed to publish ai sub msg", camera_name)
})?;
AnyResult::Ok(())
}.await;
Expand Down

0 comments on commit 474aaea

Please sign in to comment.