Only match on exact config name in some cases (#16704)

* Only match on exact config name in some cases

* Cleanup
This commit is contained in:
Nicolas Mowen
2025-02-20 10:04:06 -06:00
committed by GitHub
parent 94a9dcede8
commit c7db0f479d
4 changed files with 14 additions and 5 deletions
+9 -2
View File
@@ -32,7 +32,9 @@ class ConfigPublisher:
class ConfigSubscriber:
"""Simplifies receiving an updated config."""
def __init__(self, topic: str) -> None:
def __init__(self, topic: str, exact=False) -> None:
self.topic = topic
self.exact = exact
self.context = zmq.Context()
self.socket = self.context.socket(zmq.SUB)
self.socket.setsockopt_string(zmq.SUBSCRIBE, topic)
@@ -42,7 +44,12 @@ class ConfigSubscriber:
"""Returns updated config or None if no update."""
try:
topic = self.socket.recv_string(flags=zmq.NOBLOCK)
return (topic, self.socket.recv_pyobj())
obj = self.socket.recv_pyobj()
if not self.exact or self.topic == topic:
return (topic, obj)
else:
return (None, None)
except zmq.ZMQError:
return (None, None)
+1 -1
View File
@@ -49,7 +49,7 @@ class ImprovedMotionDetector(MotionDetector):
self.contrast_values = np.zeros((contrast_frame_history, 2), np.uint8)
self.contrast_values[:, 1:2] = 255
self.contrast_values_index = 0
self.config_subscriber = ConfigSubscriber(f"config/motion/{name}")
self.config_subscriber = ConfigSubscriber(f"config/motion/{name}", True)
self.ptz_metrics = ptz_metrics
self.last_stop_time = None
+3 -1
View File
@@ -172,7 +172,9 @@ class PreviewRecorder:
# create communication for finished previews
self.requestor = InterProcessRequestor()
self.config_subscriber = ConfigSubscriber(f"config/record/{self.config.name}")
self.config_subscriber = ConfigSubscriber(
f"config/record/{self.config.name}", True
)
y, u1, u2, v1, v2 = get_yuv_crop(
self.config.frame_shape_yuv,
+1 -1
View File
@@ -539,7 +539,7 @@ def process_frames(
exit_on_empty: bool = False,
):
next_region_update = get_tomorrow_at_time(2)
config_subscriber = ConfigSubscriber(f"config/detect/{camera_name}")
config_subscriber = ConfigSubscriber(f"config/detect/{camera_name}", True)
fps_tracker = EventsPerSecond()
fps_tracker.start()