From bfe20433f9c4cbffa5744912fd242bcd0b079607 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Wed, 16 Nov 2022 08:05:56 -0500 Subject: [PATCH] mqtt: update compatibility with latest client Signed-off-by: Eric Callahan --- moonraker/components/mqtt.py | 40 ++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/moonraker/components/mqtt.py b/moonraker/components/mqtt.py index 31f396b..efd593a 100644 --- a/moonraker/components/mqtt.py +++ b/moonraker/components/mqtt.py @@ -54,22 +54,36 @@ class ExtPahoClient(paho_mqtt.Client): if self._port <= 0: raise ValueError('Invalid port number.') - self._in_packet = { - "command": 0, - "have_remaining": 0, - "remaining_count": [], - "remaining_mult": 1, - "remaining_length": 0, - "packet": b"", - "to_process": 0, - "pos": 0} + if hasattr(self, "_out_packet_mutex"): + # Paho Mqtt Version < 1.6.x + self._in_packet = { + "command": 0, + "have_remaining": 0, + "remaining_count": [], + "remaining_mult": 1, + "remaining_length": 0, + "packet": b"", + "to_process": 0, + "pos": 0 + } + with self._out_packet_mutex: + self._out_packet = deque() # type: ignore - with self._out_packet_mutex: + with self._current_out_packet_mutex: + self._current_out_packet = None + else: + self._in_packet = { + "command": 0, + "have_remaining": 0, + "remaining_count": [], + "remaining_mult": 1, + "remaining_length": 0, + "packet": bytearray(b""), + "to_process": 0, + "pos": 0 + } self._out_packet = deque() # type: ignore - with self._current_out_packet_mutex: - self._current_out_packet = None - with self._msgtime_mutex: self._last_msg_in = paho_mqtt.time_func() self._last_msg_out = paho_mqtt.time_func()