Skip to content

Commit

Permalink
fixed topic population in subscribe() for tuple/list type topics
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohaib90 committed Jan 19, 2023
1 parent f7fc878 commit 9d6c2e9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 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,12 @@ 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)
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 9d6c2e9

Please sign in to comment.