Skip to content

Commit 687c1e5

Browse files
committed
_wait_for_msg() should return message type
1 parent 926846c commit 687c1e5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,16 +1037,17 @@ def _wait_for_msg(self) -> Optional[int]:
10371037
if res in [None, b"", b"\x00"]:
10381038
# If we get here, it means that there is nothing to be received
10391039
return None
1040-
if res[0] & MQTT_PKT_TYPE_MASK == MQTT_PINGRESP:
1040+
pkt_type = res[0] & MQTT_PKT_TYPE_MASK
1041+
self.logger.debug(f"Got message type: {hex(pkt_type)} pkt: {hex(res[0])}")
1042+
if pkt_type == MQTT_PINGRESP:
10411043
self.logger.debug("Got PINGRESP")
10421044
sz = self._sock_exact_recv(1)[0]
10431045
if sz != 0x00:
10441046
raise MMQTTException(f"Unexpected PINGRESP returned from broker: {sz}.")
1045-
return MQTT_PINGRESP
1047+
return pkt_type
10461048

1047-
if res[0] & MQTT_PKT_TYPE_MASK != MQTT_PUBLISH:
1048-
self.logger.debug(f"Got message type: {hex(res[0])}")
1049-
return res[0]
1049+
if pkt_type != MQTT_PUBLISH:
1050+
return pkt_type
10501051

10511052
# Handle only the PUBLISH packet type from now on.
10521053
sz = self._recv_len()
@@ -1080,7 +1081,7 @@ def _wait_for_msg(self) -> Optional[int]:
10801081
elif res[0] & 6 == 4:
10811082
assert 0
10821083

1083-
return res[0]
1084+
return pkt_type
10841085

10851086
def _recv_len(self) -> int:
10861087
"""Unpack MQTT message length."""

0 commit comments

Comments
 (0)