From 1c16efbea80cc12f3786e7b998ae272643e70e39 Mon Sep 17 00:00:00 2001 From: mrlt8 <67088095+mrlt8@users.noreply.github.com> Date: Sun, 12 Nov 2023 20:26:48 -0800 Subject: [PATCH] run health check on streams #1036 #1037 --- app/wyzebridge/stream.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/wyzebridge/stream.py b/app/wyzebridge/stream.py index 2b4aafaf..d55093c6 100644 --- a/app/wyzebridge/stream.py +++ b/app/wyzebridge/stream.py @@ -107,7 +107,7 @@ def monitor_streams(self, mtx_health: Callable) -> None: events = WyzeEvents(self.streams) if MOTION else None while not self.stop_flag: event.read(timeout=1) - self.snap_all() + self.snap_all(self.active_streams()) if events: events.check_motion() if int(time.time()) % 15 == 0: @@ -138,22 +138,23 @@ def active_streams(self) -> list[str]: """ return [cam for cam, s in self.streams.items() if s.health_check() > 0] - def snap_all(self, force: bool = False): + def snap_all(self, cams: Optional[list[str]] = None, force: bool = False): """ - Take an rtsp snapshot of active_streams. + Take an rtsp snapshot of the streams in the list. Args: + - cams (list[str], optional): names of the streams to take a snapshot of. - force (bool, optional): Ignore interval and force snapshot. Defaults to False. - """ - if force or ( - SNAPSHOT_TYPE == "rtsp" and time.time() - self.last_snap >= SNAPSHOT_INT - ): + if force or self._should_snap(): self.last_snap = time.time() - for cam in self.active_streams(): + for cam in cams or self.active_streams(): stop_subprocess(self.rtsp_snapshots.get(cam)) self.rtsp_snap_popen(cam, True) + def _should_snap(self): + return SNAPSHOT_TYPE == "rtsp" and time.time() - self.last_snap >= SNAPSHOT_INT + def get_sse_status(self) -> dict: return { uri: {"status": cam.status(), "motion": cam.motion} @@ -177,7 +178,7 @@ def send_cmd( resp = {"status": "error", "command": cmd, "payload": payload} if cam_name == "all" and cmd == "update_snapshot": - self.snap_all(True) + self.snap_all(force=True) return resp | {"status": "success"} if not (stream := self.get(cam_name)):