6666MQTT_PINGRESP = const (0xD0 )
6767MQTT_PUBLISH = const (0x30 )
6868MQTT_SUB = const (0x82 )
69+ MQTT_SUBACK = const (0x90 )
6970MQTT_UNSUB = const (0xA2 )
71+ MQTT_UNSUBACK = const (0xB0 )
7072MQTT_DISCONNECT = b"\xe0 \0 "
7173
7274MQTT_PKT_TYPE_MASK = const (0xF0 )
@@ -801,7 +803,7 @@ def subscribe( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
801803 f"No data received from broker for { self ._recv_timeout } seconds."
802804 )
803805 else :
804- if op == 0x90 :
806+ if op == MQTT_SUBACK :
805807 remaining_len = self ._decode_remaining_length ()
806808 assert remaining_len > 0
807809 rc = self ._sock_exact_recv (2 )
@@ -879,7 +881,7 @@ def unsubscribe( # noqa: PLR0912, Too many branches
879881 f"No data received from broker for { self ._recv_timeout } seconds."
880882 )
881883 else :
882- if op == 176 :
884+ if op == MQTT_UNSUBACK :
883885 rc = self ._sock_exact_recv (3 )
884886 assert rc [0 ] == 0x02
885887 # [MQTT-3.32]
@@ -889,10 +891,12 @@ def unsubscribe( # noqa: PLR0912, Too many branches
889891 self .on_unsubscribe (self , self .user_data , t , self ._pid )
890892 self ._subscribed_topics .remove (t )
891893 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+ )
896900
897901 def _recompute_reconnect_backoff (self ) -> None :
898902 """
0 commit comments