Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Paho API Version 2 #538

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion insteon_mqtt/cmd_line/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def send(config, topic, payload, quiet=False):
"quiet" : int(quiet),
}

client = mqtt.Client(userdata=session)
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, userdata=session)

# Add user/password if the config file has them set.
if config["mqtt"].get("username", None):
Expand Down
16 changes: 10 additions & 6 deletions insteon_mqtt/network/Mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ def setup_client(self):
""" Create or reinitialise the MQTT client and set the callbacks.
"""

client_args = {'client_id': self.id, 'clean_session': False}
client_args = {
'callback_api_version': paho.CallbackAPIVersion.VERSION2,
'client_id': self.id,
'clean_session': False
}

if not hasattr(self, 'client'):
self.client = paho.Client(**client_args)
Expand Down Expand Up @@ -385,7 +389,7 @@ def close(self):
self.signal_needs_write.emit(self, True)

#-----------------------------------------------------------------------
def _on_connect(self, client, data, flags, result):
def _on_connect(self, client, userdata, flags, reason_code, properties):
"""MQTT connection callback.

This is called by the MQTT client once the connection has occurred.
Expand All @@ -398,20 +402,20 @@ def _on_connect(self, client, data, flags, result):
client, 3 = server unavailable, 4 = bad login, 5 = not
authorized.
"""
if result == 0:
if reason_code == 0:
self.connected = True
self.signal_connected.emit(self, True)
self.client.publish(self.availability_topic, payload="online",
qos=0, retain=True)
else:
LOG.error("MQTT connection refused %s %s %s", self.host, self.port,
result)
reason_code)

#-----------------------------------------------------------------------
def _on_disconnect(self, client, data, result):
def _on_disconnect(self, client, userdata, flags, reason_code, properties):
"""MQTT disconnection callback.

This is called by the MQTT client when the connection is droppped.
This is called by the MQTT client when the connection is dropped.

Args:
client (paho.Client): The paho mqtt client (self.client).
Expand Down
Loading