Skip to content

Commit

Permalink
Merge pull request #125 from Sohaib90/unsub_bug
Browse files Browse the repository at this point in the history
fixed topic population in subscribe() for tuple/list type topics
  • Loading branch information
Sohaib90 authored Jan 19, 2023
2 parents f7fc878 + 60df092 commit f0af5c5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions flask_mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def decorator(handler: Callable[[str], None]) -> Callable[[str], None]:

return decorator

def subscribe(self, topic: str, qos: int = 0) -> Tuple[int, int]:
def subscribe(self, topic, qos: int = 0) -> Tuple[int, int]:
"""
Subscribe to a certain topic.
Expand Down Expand Up @@ -311,7 +311,14 @@ def subscribe(self, topic: str, qos: int = 0) -> Tuple[int, int]:

# if successful add to topics
if result == MQTT_ERR_SUCCESS:
self.topics[topic] = TopicQos(topic=topic, qos=qos)
if isinstance(topic, tuple):
topic, qos = topic
self.topics[topic] = TopicQos(topic=topic, qos=qos)
elif isinstance(topic, list):
for t, q in topic:
self.topics[t] = TopicQos(topic=t, qos=q)
else:
self.topics[topic] = TopicQos(topic=topic, qos=qos)
logger.debug("Subscribed to topic: {0}, qos: {1}".format(topic, qos))
else:
logger.error("Error {0} subscribing to topic: {1}".format(result, topic))
Expand Down

0 comments on commit f0af5c5

Please sign in to comment.