Skip to content

Commit

Permalink
update callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Aug 19, 2024
1 parent 555de1d commit 53515fb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pywis_pubsub/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def __init__(self, broker: str, options: dict = {}) -> None:

msg = f'Connecting to broker {self.broker_safe_url} with id {self.client_id}' # noqa
LOGGER.debug(msg)
self.conn = mqtt_client.Client(self.client_id,
self.conn = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION2,
self.client_id,
userdata=self.userdata,
transport=transport)

Expand Down Expand Up @@ -141,15 +142,16 @@ def sub(self, topics: list, qos: int = 1) -> None:
:returns: `None`
"""

def on_connect(client, userdata, flags, rc):
def on_connect(client, userdata, flags, reason_code, properties):
LOGGER.debug(f'Connected to broker {self.broker_safe_url}')
LOGGER.debug(f'Subscribing to topics {topics}')
for topic in topics:
client.subscribe(topic, qos=qos)
LOGGER.debug(f'Subscribed to topic {topic}, qos {qos}')

def on_disconnect(client, userdata, rc):
LOGGER.debug(f'Disconnected from {self.broker_safe_url}: ({rc})')
def on_disconnect(client, userdata, flags, reason_code, properties):
msg = f'Disconnected from {self.broker_safe_url}: ({reason_code})'
LOGGER.debug(msg)

LOGGER.debug(f'Subscribing to broker {self.broker_safe_url}, topic(s) {topics}') # noqa
self.conn.on_connect = on_connect
Expand Down

0 comments on commit 53515fb

Please sign in to comment.