From 121b90a4983154282fa1119f50fd4809105aad61 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Tue, 22 Nov 2022 14:10:09 -0700 Subject: [PATCH] Cleanup --- frigate/communication/mqtt.py | 19 +++++++++---------- frigate/communication/ws.py | 8 ++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/frigate/communication/mqtt.py b/frigate/communication/mqtt.py index c85a09ca3..f4653b279 100644 --- a/frigate/communication/mqtt.py +++ b/frigate/communication/mqtt.py @@ -5,7 +5,6 @@ import paho.mqtt.client as mqtt from frigate.communication.dispatcher import Communicator from frigate.config import FrigateConfig -from frigate.types import CameraMetricsTypes logger = logging.getLogger(__name__) @@ -38,48 +37,48 @@ class MqttClient(Communicator): """Set initial state topics.""" for camera_name, camera in self.config.cameras.items(): self.publish( - f"{self.mqtt_config.topic_prefix}/{camera_name}/recordings/state", + f"{camera_name}/recordings/state", "ON" if camera.record.enabled else "OFF", retain=True, ) self.publish( - f"{self.mqtt_config.topic_prefix}/{camera_name}/snapshots/state", + f"{camera_name}/snapshots/state", "ON" if camera.snapshots.enabled else "OFF", retain=True, ) self.publish( - f"{self.mqtt_config.topic_prefix}/{camera_name}/detect/state", + f"{camera_name}/detect/state", "ON" if camera.detect.enabled else "OFF", retain=True, ) self.publish( - f"{self.mqtt_config.topic_prefix}/{camera_name}/motion/state", + f"{camera_name}/motion/state", "ON", retain=True, ) self.publish( - f"{self.mqtt_config.topic_prefix}/{camera_name}/improve_contrast/state", + f"{camera_name}/improve_contrast/state", "ON" if camera.motion.improve_contrast else "OFF", retain=True, ) self.publish( - f"{self.mqtt_config.topic_prefix}/{camera_name}/motion_threshold/state", + f"{camera_name}/motion_threshold/state", camera.motion.threshold, retain=True, ) self.publish( - f"{self.mqtt_config.topic_prefix}/{camera_name}/motion_contour_area/state", + f"{camera_name}/motion_contour_area/state", camera.motion.contour_area, retain=True, ) self.publish( - f"{self.mqtt_config.topic_prefix}/{camera_name}/motion", + f"{camera_name}/motion", "OFF", retain=False, ) self.publish( - self.mqtt_config.topic_prefix + "/available", "online", retain=True + "available", "online", retain=True ) def on_mqtt_command( diff --git a/frigate/communication/ws.py b/frigate/communication/ws.py index 561460fff..4a39116d4 100644 --- a/frigate/communication/ws.py +++ b/frigate/communication/ws.py @@ -39,12 +39,13 @@ class WebSocketClient(Communicator): try: json_message = json.loads(message.data.decode("utf-8")) json_message = { - "topic": f"{self.topic_prefix}/{json_message['topic']}", + "topic": json_message.get("topic"), "payload": json_message.get("payload"), - "retain": json_message.get("retain", False), } except Exception as e: - logger.warning("Unable to parse websocket message as valid json.") + logger.warning( + f"Unable to parse websocket message as valid json: {message.data.decode('utf-8')}" + ) return logger.debug( @@ -53,7 +54,6 @@ class WebSocketClient(Communicator): self.receiver( json_message["topic"], json_message["payload"], - retain=json_message["retain"], ) # start a websocket server on 5002