Compare commits

...
Author SHA1 Message Date
QuantumEntangledAndy 5cec02e3c2 Use a central UID system for push notifications 2023-10-29 17:24:21 +07:00
QuantumEntangledAndy 4a94a2ddb2 README.md 2023-10-28 12:20:11 +07:00
4 changed files with 41 additions and 4 deletions

No files matched your search

+1
View File
@@ -371,6 +371,7 @@ Avaliable features are:
- `pt`: This adds a selection of buttons to control the pan and tilt of the
camera
- `battery`: This adds a battery level sensor to home assistant
- `siren`: Adds a siren button to home assistant
### Pause
+9 -3
View File
@@ -261,10 +261,16 @@ impl NeoInstance {
Ok(instance_rx.await?)
}
pub(crate) async fn push_notifications(&self) -> Result<WatchReceiver<Option<PushNoti>>> {
let uid = self
.run_task(|cam| Box::pin(async move { Ok(cam.uid().await?) }))
pub(crate) async fn uid(&self) -> Result<String> {
let (reply_tx, reply_rx) = oneshot();
self.camera_control
.send(NeoCamCommand::GetUid(reply_tx))
.await?;
Ok(reply_rx.await?)
}
pub(crate) async fn push_notifications(&self) -> Result<WatchReceiver<Option<PushNoti>>> {
let uid = self.uid().await?;
let (instance_tx, instance_rx) = oneshot();
self.camera_control
.send(NeoCamCommand::PushNoti(instance_tx))
+30
View File
@@ -41,6 +41,7 @@ pub(crate) enum NeoCamCommand {
State(OneshotSender<NeoCamThreadState>),
GetPermit(OneshotSender<Permit>),
PushNoti(OneshotSender<WatchReceiver<Option<PushNoti>>>),
GetUid(OneshotSender<String>),
}
/// The underlying camera binding
pub(crate) struct NeoCam {
@@ -62,6 +63,7 @@ impl NeoCam {
let (stream_request_tx, stream_request_rx) = mpsc(100);
let (md_request_tx, md_request_rx) = mpsc(100);
let (state_tx, state_rx) = watch(NeoCamThreadState::Connected);
let (uid_tx, uid_rx) = watch(config.camera_uid.clone());
let set = JoinSet::new();
let users = UseCounter::new().await;
@@ -175,6 +177,14 @@ impl NeoCam {
}
).await?;
},
NeoCamCommand::GetUid(sender) => {
let mut uid_rx = uid_rx.clone();
tokio::task::spawn(async move {
let uid = uid_rx.wait_for(|v| v.is_some()).await?.clone().unwrap();
let _ = sender.send(uid);
AnyResult::Ok(())
});
},
}
}
log::debug!("Control thread Senders dropped");
@@ -275,6 +285,26 @@ impl NeoCam {
}
});
// This thread will update the UID by asking the camera.
// We cache this in the uid_rx
let uid_instance = instance.clone();
let uid_cancel = me.cancel.clone();
me.set.spawn(async move {
tokio::select! {
_ = uid_cancel.cancelled() => {
AnyResult::Ok(())
},
v = async {
let uid = uid_instance.run_task(|cam| Box::pin(async move {
let uid = cam.uid().await?;
Ok(uid)
})).await?;
uid_tx.send_replace(Some(uid));
AnyResult::Ok(())
} => v,
}
});
// Handles push notifications
let pn_root_instance = instance.subscribe().await?;
let pn_cancel = me.cancel.clone();
+1 -1
View File
@@ -565,7 +565,7 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
} => v,
// Handle the floodlight task activation
v = async {
let flt_status = camera_floodlight_tasks.run_task(|cam| Box::pin(async move {
let flt_status = camera_floodlight_tasks.run_passive_task(|cam| Box::pin(async move {
Ok(cam.is_flightlight_tasks_enabled().await?)
})).await;
if flt_status.is_err() {