Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions adafruit_minimqtt/adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
MQTT_PINGRESP = const(0xD0)
MQTT_PUBLISH = const(0x30)
MQTT_SUB = const(0x82)
MQTT_SUBACK = const(0x90)
MQTT_UNSUB = const(0xA2)
MQTT_UNSUBACK = const(0xB0)
MQTT_DISCONNECT = b"\xe0\0"

MQTT_PKT_TYPE_MASK = const(0xF0)
Expand Down Expand Up @@ -774,7 +776,7 @@ def subscribe( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
f"No data received from broker for {self._recv_timeout} seconds."
)
else:
if op == 0x90:
if op == MQTT_SUBACK:
remaining_len = self._decode_remaining_length()
assert remaining_len > 0
rc = self._sock_exact_recv(2)
Expand Down Expand Up @@ -852,7 +854,7 @@ def unsubscribe( # noqa: PLR0912, Too many branches
f"No data received from broker for {self._recv_timeout} seconds."
)
else:
if op == 176:
if op == MQTT_UNSUBACK:
rc = self._sock_exact_recv(3)
assert rc[0] == 0x02
# [MQTT-3.32]
Expand All @@ -862,10 +864,10 @@ def unsubscribe( # noqa: PLR0912, Too many branches
self.on_unsubscribe(self, self.user_data, t, self._pid)
self._subscribed_topics.remove(t)
return

raise MMQTTException(
f"invalid message received as response to UNSUBSCRIBE: {hex(op)}"
)
if op != MQTT_PUBLISH:
raise MMQTTException(
Copy link
Contributor

@vladak vladak Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to add a comment similar to the one in subscribe(), explain the rationale.

f"invalid message received as response to UNSUBSCRIBE: {hex(op)}"
)

def _recompute_reconnect_backoff(self) -> None:
"""
Expand Down