66
66
MQTT_PINGRESP = const (0xD0 )
67
67
MQTT_PUBLISH = const (0x30 )
68
68
MQTT_SUB = const (0x82 )
69
+ MQTT_SUBACK = const (0x90 )
69
70
MQTT_UNSUB = const (0xA2 )
71
+ MQTT_UNSUBACK = const (0xB0 )
70
72
MQTT_DISCONNECT = b"\xe0 \0 "
71
73
72
74
MQTT_PKT_TYPE_MASK = const (0xF0 )
@@ -801,7 +803,7 @@ def subscribe( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
801
803
f"No data received from broker for { self ._recv_timeout } seconds."
802
804
)
803
805
else :
804
- if op == 0x90 :
806
+ if op == MQTT_SUBACK :
805
807
remaining_len = self ._decode_remaining_length ()
806
808
assert remaining_len > 0
807
809
rc = self ._sock_exact_recv (2 )
@@ -879,7 +881,7 @@ def unsubscribe( # noqa: PLR0912, Too many branches
879
881
f"No data received from broker for { self ._recv_timeout } seconds."
880
882
)
881
883
else :
882
- if op == 176 :
884
+ if op == MQTT_UNSUBACK :
883
885
rc = self ._sock_exact_recv (3 )
884
886
assert rc [0 ] == 0x02
885
887
# [MQTT-3.32]
@@ -889,10 +891,12 @@ def unsubscribe( # noqa: PLR0912, Too many branches
889
891
self .on_unsubscribe (self , self .user_data , t , self ._pid )
890
892
self ._subscribed_topics .remove (t )
891
893
return
892
-
893
- raise MMQTTException (
894
- f"invalid message received as response to UNSUBSCRIBE: { hex (op )} "
895
- )
894
+ if op != MQTT_PUBLISH :
895
+ # [3.10.4] The Server may continue to deliver existing messages buffered
896
+ # for delivery to the client prior to sending the UNSUBACK Packet.
897
+ raise MMQTTException (
898
+ f"invalid message received as response to UNSUBSCRIBE: { hex (op )} "
899
+ )
896
900
897
901
def _recompute_reconnect_backoff (self ) -> None :
898
902
"""
0 commit comments