Skip to content

Commit

Permalink
Merge pull request #538 from krkeegan/pahov2_upgrade
Browse files Browse the repository at this point in the history
Migrate to Paho API Version 2
  • Loading branch information
krkeegan authored Jan 13, 2025
2 parents 6d6c3a2 + cae1dfb commit 41ff41c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
paho-mqtt>=1.3
paho-mqtt>=2.0
pyserial>=3.2
pyyaml>=3
Jinja2>=2.1
Expand Down

0 comments on commit 41ff41c

Please sign in to comment.