diff --git a/pyproject.toml b/pyproject.toml index e63e7b1..393797d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,7 +78,7 @@ dev = [ "types-pyserial", "pytest", "pytest-cov", - "types-paho-mqtt", + "paho-mqtt >=2,<3" ] vision = ["opencv-python-headless >=4,<5"] -mqtt = ["paho-mqtt >=1.6,<2"] +mqtt = ["paho-mqtt >=2,<3"] diff --git a/sbot/mqtt.py b/sbot/mqtt.py index f7ccd82..62a2e37 100644 --- a/sbot/mqtt.py +++ b/sbot/mqtt.py @@ -20,7 +20,7 @@ def __init__( self, client_name: str | None = None, topic_prefix: str | None = None, - mqtt_version: int = mqtt.MQTTv5, + mqtt_version: mqtt.MQTTProtocolVersion = mqtt.MQTTProtocolVersion.MQTTv5, use_tls: bool | str = False, username: str = '', password: str = '', @@ -32,7 +32,11 @@ def __init__( self._client_name = client_name self._img_topic = 'img' - self._client = mqtt.Client(client_id=client_name, protocol=mqtt_version) + self._client = mqtt.Client( + callback_api_version=mqtt.CallbackAPIVersion.VERSION2, + client_id=client_name, + protocol=mqtt_version, + ) self._client.on_connect = self._on_connect if use_tls: @@ -150,12 +154,17 @@ def wrapped_publish( retain=retain, abs_topic=abs_topic) def _on_connect( - self, client: mqtt.Client, userdata: Any, flags: dict[str, int], rc: int, + self, + client: mqtt.Client, + userdata: Any, + connect_flags: mqtt.ConnectFlags, + reason_code: mqtt.ReasonCode, properties: mqtt.Properties | None = None, ) -> None: - if rc != mqtt.CONNACK_ACCEPTED: + if reason_code.is_failure: LOGGER.warning( - f"Failed to connect to MQTT broker. Return code: {mqtt.error_string(rc)}" + "Failed to connect to MQTT broker. " + f"Return code: {reason_code.getName()}" # type: ignore[no-untyped-call] ) return