NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Update and migrate mqtt to v2 (#10160)
Nicolas Mowenea9316e770b7
diff --git a/frigate/comms/mqtt.py b/frigate/comms/mqtt.pyindex 6182c89e37..b83484d417 100644--- a/frigate/comms/mqtt.py+++ b/frigate/comms/mqtt.py@@ -3,6 +3,7 @@ import threadingfrom typing import Any, Callableimport paho.mqtt.client as mqtt+from paho.mqtt.enums import CallbackAPIVersionfrom frigate.comms.dispatcher import Communicatorfrom frigate.config import FrigateConfig@@ -96,9 +97,11 @@ class MqttClient(Communicator): # type: ignore[misc])self.publish(f"{camera_name}/birdseye_mode/state",- camera.birdseye.mode.value.upper()- if camera.birdseye.enabled- else "OFF",+ (+ camera.birdseye.mode.value.upper()+ if camera.birdseye.enabled+ else "OFF"+ ),retain=True,)@@ -117,25 +120,26 @@ class MqttClient(Communicator): # type: ignore[misc]client: mqtt.Client,userdata: Any,flags: Any,- rc: mqtt.ReasonCodes,+ reason_code: mqtt.ReasonCode,+ properties: Any,) -> None:"""Mqtt connection callback."""threading.current_thread().name = "mqtt"- if rc != 0:- if rc == 3:+ if reason_code != 0:+ if reason_code == "Server Unavailable":logger.error("Unable to connect to MQTT server: MQTT Server unavailable")- elif rc == 4:+ elif reason_code == "Bad user name or password":logger.error("Unable to connect to MQTT server: MQTT Bad username or password")- elif rc == 5:+ elif reason_code == "Not authorized":logger.error("Unable to connect to MQTT server: MQTT Not authorized")else:logger.error("Unable to connect to MQTT server: Connection refused. Error code: "- + str(rc)+ + reason_code.getName())self.connected = True@@ -144,7 +148,12 @@ class MqttClient(Communicator): # type: ignore[misc]self._set_initial_topics()def _on_disconnect(- self, client: mqtt.Client, userdata: Any, flags: Any, rc: mqtt+ self,+ client: mqtt.Client,+ userdata: Any,+ flags: Any,+ reason_code: mqtt.ReasonCode,+ properties: Any,) -> None:"""Mqtt disconnection callback."""self.connected = False@@ -152,7 +161,10 @@ class MqttClient(Communicator): # type: ignore[misc]def _start(self) -> None:"""Start mqtt client."""- self.client = mqtt.Client(client_id=self.mqtt_config.client_id)+ self.client = mqtt.Client(+ callback_api_version=CallbackAPIVersion.VERSION2,+ client_id=self.mqtt_config.client_id,+ )self.client.on_connect = self._on_connectself.client.will_set(self.mqtt_config.topic_prefix + "/available",