From 0250db70d015044246fcf137dc8213099c4af316 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Fri, 6 Jun 2025 08:56:04 -0600 Subject: [PATCH] Cleanup detections updater --- frigate/comms/config_updater.py | 2 +- frigate/comms/detections_updater.py | 14 ++++++-------- frigate/comms/zmq_proxy.py | 2 +- frigate/embeddings/maintainer.py | 2 +- frigate/events/audio.py | 2 +- frigate/output/output.py | 2 +- frigate/record/maintainer.py | 8 ++++---- frigate/review/maintainer.py | 8 ++++---- frigate/track/object_processing.py | 2 +- 9 files changed, 20 insertions(+), 22 deletions(-) diff --git a/frigate/comms/config_updater.py b/frigate/comms/config_updater.py index 12471272d..447089a94 100644 --- a/frigate/comms/config_updater.py +++ b/frigate/comms/config_updater.py @@ -3,7 +3,7 @@ import multiprocessing as mp from _pickle import UnpicklingError from multiprocessing.synchronize import Event as MpEvent -from typing import Any, Optional +from typing import Any import zmq diff --git a/frigate/comms/detections_updater.py b/frigate/comms/detections_updater.py index 1718d1347..adb3b1153 100644 --- a/frigate/comms/detections_updater.py +++ b/frigate/comms/detections_updater.py @@ -1,7 +1,7 @@ """Facilitates communication between processes.""" from enum import Enum -from typing import Any, Optional +from typing import Any from .zmq_proxy import Publisher, Subscriber @@ -19,8 +19,7 @@ class DetectionPublisher(Publisher): topic_base = "detection/" - def __init__(self, topic: DetectionTypeEnum) -> None: - topic = topic.value + def __init__(self, topic: str) -> None: super().__init__(topic) @@ -29,16 +28,15 @@ class DetectionSubscriber(Subscriber): topic_base = "detection/" - def __init__(self, topic: DetectionTypeEnum) -> None: - topic = topic.value + def __init__(self, topic: str) -> None: super().__init__(topic) def check_for_update( - self, timeout: float = None - ) -> Optional[tuple[DetectionTypeEnum, Any]]: + self, timeout: float | None = None + ) -> tuple[str, Any] | tuple[None, None]: return super().check_for_update(timeout) def _return_object(self, topic: str, payload: Any) -> Any: if payload is None: return (None, None) - return (DetectionTypeEnum[topic[len(self.topic_base) :]], payload) + return (topic[len(self.topic_base) :], payload) diff --git a/frigate/comms/zmq_proxy.py b/frigate/comms/zmq_proxy.py index 429bb8df4..10ee3afec 100644 --- a/frigate/comms/zmq_proxy.py +++ b/frigate/comms/zmq_proxy.py @@ -83,7 +83,7 @@ class Subscriber: self.socket.connect(SOCKET_SUB) def check_for_update( - self, timeout: float = FAST_QUEUE_TIMEOUT + self, timeout: float | None = FAST_QUEUE_TIMEOUT ) -> tuple[str, Any] | tuple[None, None]: """Returns message or None if no update.""" try: diff --git a/frigate/embeddings/maintainer.py b/frigate/embeddings/maintainer.py index 66c87dc5f..13315b2de 100644 --- a/frigate/embeddings/maintainer.py +++ b/frigate/embeddings/maintainer.py @@ -143,7 +143,7 @@ class EmbeddingMaintainer(threading.Thread): self.recordings_subscriber = RecordingsDataSubscriber( RecordingsDataTypeEnum.recordings_available_through ) - self.detection_subscriber = DetectionSubscriber(DetectionTypeEnum.video) + self.detection_subscriber = DetectionSubscriber(DetectionTypeEnum.video.value) self.embeddings_responder = EmbeddingsResponder() self.frame_manager = SharedMemoryFrameManager() diff --git a/frigate/events/audio.py b/frigate/events/audio.py index 36b5a9ccd..cb1fe392b 100644 --- a/frigate/events/audio.py +++ b/frigate/events/audio.py @@ -183,7 +183,7 @@ class AudioEventMaintainer(threading.Thread): CameraConfigUpdateEnum.audio_transcription, ], ) - self.detection_publisher = DetectionPublisher(DetectionTypeEnum.audio) + self.detection_publisher = DetectionPublisher(DetectionTypeEnum.audio.value) self.event_metadata_publisher = EventMetadataPublisher() if self.camera_config.audio_transcription.enabled_in_config: diff --git a/frigate/output/output.py b/frigate/output/output.py index 4d7ff2466..674c02b78 100644 --- a/frigate/output/output.py +++ b/frigate/output/output.py @@ -96,7 +96,7 @@ class OutputProcess(FrigateProcess): websocket_server.initialize_websockets_manager() websocket_thread = threading.Thread(target=websocket_server.serve_forever) - detection_subscriber = DetectionSubscriber(DetectionTypeEnum.video) + detection_subscriber = DetectionSubscriber(DetectionTypeEnum.video.value) config_subscriber = CameraConfigUpdateSubscriber( self.config, self.config.cameras, diff --git a/frigate/record/maintainer.py b/frigate/record/maintainer.py index 0883437da..c1a84d299 100644 --- a/frigate/record/maintainer.py +++ b/frigate/record/maintainer.py @@ -79,7 +79,7 @@ class RecordingMaintainer(threading.Thread): self.config.cameras, [CameraConfigUpdateEnum.add, CameraConfigUpdateEnum.record], ) - self.detection_subscriber = DetectionSubscriber(DetectionTypeEnum.all) + self.detection_subscriber = DetectionSubscriber(DetectionTypeEnum.all.value) self.recordings_publisher = RecordingsDataPublisher( RecordingsDataTypeEnum.recordings_available_through ) @@ -545,7 +545,7 @@ class RecordingMaintainer(threading.Thread): if not topic: break - if topic == DetectionTypeEnum.video: + if topic == DetectionTypeEnum.video.value: ( camera, _, @@ -564,7 +564,7 @@ class RecordingMaintainer(threading.Thread): regions, ) ) - elif topic == DetectionTypeEnum.audio: + elif topic == DetectionTypeEnum.audio.value: ( camera, frame_time, @@ -580,7 +580,7 @@ class RecordingMaintainer(threading.Thread): audio_detections, ) ) - elif topic == DetectionTypeEnum.api or DetectionTypeEnum.lpr: + elif topic == DetectionTypeEnum.api.value or DetectionTypeEnum.lpr.value: continue if frame_time < run_start - stale_frame_count_threshold: diff --git a/frigate/review/maintainer.py b/frigate/review/maintainer.py index 778717db3..c476824f2 100644 --- a/frigate/review/maintainer.py +++ b/frigate/review/maintainer.py @@ -164,7 +164,7 @@ class ReviewSegmentMaintainer(threading.Thread): CameraConfigUpdateEnum.review, ], ) - self.detection_subscriber = DetectionSubscriber(DetectionTypeEnum.all) + self.detection_subscriber = DetectionSubscriber(DetectionTypeEnum.all.value) # manual events self.indefinite_events: dict[str, dict[str, Any]] = {} @@ -484,7 +484,7 @@ class ReviewSegmentMaintainer(threading.Thread): if not topic: continue - if topic == DetectionTypeEnum.video: + if topic == DetectionTypeEnum.video.value: ( camera, frame_name, @@ -493,14 +493,14 @@ class ReviewSegmentMaintainer(threading.Thread): _, _, ) = data - elif topic == DetectionTypeEnum.audio: + elif topic == DetectionTypeEnum.audio.value: ( camera, frame_time, _, audio_detections, ) = data - elif topic == DetectionTypeEnum.api or DetectionTypeEnum.lpr: + elif topic == DetectionTypeEnum.api.value or DetectionTypeEnum.lpr.value: ( camera, frame_time, diff --git a/frigate/track/object_processing.py b/frigate/track/object_processing.py index 8e8836278..25e174feb 100644 --- a/frigate/track/object_processing.py +++ b/frigate/track/object_processing.py @@ -78,7 +78,7 @@ class TrackedObjectProcessor(threading.Thread): ) self.requestor = InterProcessRequestor() - self.detection_publisher = DetectionPublisher(DetectionTypeEnum.all) + self.detection_publisher = DetectionPublisher(DetectionTypeEnum.all.value) self.event_sender = EventUpdatePublisher() self.event_end_subscriber = EventEndSubscriber() self.sub_label_subscriber = EventMetadataSubscriber(EventMetadataTypeEnum.all)