@@ -241,7 +241,7 @@ def __init__( # noqa: PLR0915, PLR0913, Too many statements, Too many arguments
241241 self ._lw_retain = False
242242
243243 # List of subscribed topics, used for tracking
244- self ._subscribed_topics : List [str ] = []
244+ self ._subscribed_topics : List [tuple [ str , int ] ] = []
245245 self ._on_message_filtered = MQTTMatcher ()
246246
247247 # Default topic callback methods
@@ -837,7 +837,7 @@ def subscribe( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
837837 for t , q in topics :
838838 if self .on_subscribe is not None :
839839 self .on_subscribe (self , self .user_data , t , q )
840- self ._subscribed_topics .append (t )
840+ self ._subscribed_topics .append (( t , q ) )
841841
842842 return
843843
@@ -866,7 +866,7 @@ def unsubscribe( # noqa: PLR0912, Too many branches
866866 self ._valid_topic (t )
867867 topics .append (t )
868868 for t in topics :
869- if t not in self ._subscribed_topics :
869+ if t not in [ _t for _t , _ in self ._subscribed_topics ] :
870870 raise MMQTTStateError ("Topic must be subscribed to before attempting unsubscribe." )
871871 # Assemble packet
872872 self .logger .debug ("Sending UNSUBSCRIBE to broker..." )
@@ -907,7 +907,8 @@ def unsubscribe( # noqa: PLR0912, Too many branches
907907 for t in topics :
908908 if self .on_unsubscribe is not None :
909909 self .on_unsubscribe (self , self .user_data , t , self ._pid )
910- self ._subscribed_topics .remove (t )
910+ _ , q = [(_t , _q ) for _t , _q in self ._subscribed_topics if _t == t ][0 ]
911+ self ._subscribed_topics .remove ((t , q ))
911912 return
912913 if op != MQTT_PUBLISH :
913914 # [3.10.4] The Server may continue to deliver existing messages buffered
@@ -972,7 +973,7 @@ def reconnect(self, resub_topics: bool = True) -> int:
972973 self ._subscribed_topics = []
973974 while subscribed_topics :
974975 feed = subscribed_topics .pop ()
975- self .subscribe (feed )
976+ self .subscribe (* feed )
976977
977978 return ret
978979
0 commit comments