Pre clear retained messagse (#5117)

This commit is contained in:
Nicolas Mowen 2023-01-16 16:16:46 -07:00 committed by GitHub
parent 30f520f6f0
commit 81b3fdb423
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -139,35 +139,30 @@ class MqttClient(Communicator): # type: ignore[misc]
) )
# register callbacks # register callbacks
callback_types = [
"recordings",
"snapshots",
"detect",
"motion",
"improve_contrast",
"motion_threshold",
"motion_contour_area",
]
for name in self.config.cameras.keys(): for name in self.config.cameras.keys():
self.client.message_callback_add( for callback in callback_types:
f"{self.mqtt_config.topic_prefix}/{name}/recordings/set", # We need to pre-clear existing set topics because in previous
self.on_mqtt_command, # versions the webUI retained on the /set topic but this is
) # no longer the case.
self.client.message_callback_add( self.client.publish(
f"{self.mqtt_config.topic_prefix}/{name}/snapshots/set", f"{self.mqtt_config.topic_prefix}/{name}/{callback}/set",
self.on_mqtt_command, None,
) retain=True,
self.client.message_callback_add( )
f"{self.mqtt_config.topic_prefix}/{name}/detect/set", self.client.message_callback_add(
self.on_mqtt_command, f"{self.mqtt_config.topic_prefix}/{name}/{callback}/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,
)
self.client.message_callback_add( self.client.message_callback_add(
f"{self.mqtt_config.topic_prefix}/restart", self.on_mqtt_command f"{self.mqtt_config.topic_prefix}/restart", self.on_mqtt_command