From 81b3fdb4231885053e1c6a4fef7fc31bb97da309 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 16 Jan 2023 16:16:46 -0700 Subject: [PATCH] Pre clear retained messagse (#5117) --- frigate/comms/mqtt.py | 51 +++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/frigate/comms/mqtt.py b/frigate/comms/mqtt.py index e74cc6bf2..b8c1a0ea6 100644 --- a/frigate/comms/mqtt.py +++ b/frigate/comms/mqtt.py @@ -139,35 +139,30 @@ class MqttClient(Communicator): # type: ignore[misc] ) # register callbacks + callback_types = [ + "recordings", + "snapshots", + "detect", + "motion", + "improve_contrast", + "motion_threshold", + "motion_contour_area", + ] + for name in self.config.cameras.keys(): - self.client.message_callback_add( - f"{self.mqtt_config.topic_prefix}/{name}/recordings/set", - self.on_mqtt_command, - ) - self.client.message_callback_add( - f"{self.mqtt_config.topic_prefix}/{name}/snapshots/set", - self.on_mqtt_command, - ) - self.client.message_callback_add( - f"{self.mqtt_config.topic_prefix}/{name}/detect/set", - self.on_mqtt_command, - ) - self.client.message_callback_add( - f"{self.mqtt_config.topic_prefix}/{name}/motion/set", - self.on_mqtt_command, - ) - self.client.message_callback_add( - f"{self.mqtt_config.topic_prefix}/{name}/improve_contrast/set", - self.on_mqtt_command, - ) - self.client.message_callback_add( - f"{self.mqtt_config.topic_prefix}/{name}/motion_threshold/set", - self.on_mqtt_command, - ) - self.client.message_callback_add( - f"{self.mqtt_config.topic_prefix}/{name}/motion_contour_area/set", - self.on_mqtt_command, - ) + for callback in callback_types: + # We need to pre-clear existing set topics because in previous + # versions the webUI retained on the /set topic but this is + # no longer the case. + self.client.publish( + f"{self.mqtt_config.topic_prefix}/{name}/{callback}/set", + None, + retain=True, + ) + self.client.message_callback_add( + f"{self.mqtt_config.topic_prefix}/{name}/{callback}/set", + self.on_mqtt_command, + ) self.client.message_callback_add( f"{self.mqtt_config.topic_prefix}/restart", self.on_mqtt_command