Skip to content

Commit

Permalink
Migrate paho-mqtt to version v2.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mictronics committed Jul 14, 2024
1 parent 6d23fac commit 1a99f59
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/meshtastic2hass/meshtastic2hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
__author__ = "Michael Wolf aka Mictronics"
__copyright__ = "2024, (C) Michael Wolf"
__license__ = "GPL v3+"
__version__ = "1.0.11"
__version__ = "1.0.12"


def onReceiveTelemetry(packet, interface, topic=pub.AUTO_TOPIC):
Expand Down Expand Up @@ -344,25 +344,25 @@ def onMQTTMessage(mqttc, obj, msg):
)


def onMQTTConnect(client, userdata, flags, rc):
def onMQTTConnect(client, userdata, flags, reason_code, properties):
"""Callback invoke when we connect to MQTT broker"""
if rc != 0:
print(f"MQTT: unexpected connection error {rc}")
if reason_code != 0:
print(f"MQTT: unexpected connection error {reason_code}")
_globals = Globals.getInstance()
if _globals.getLoop() is not None:
_globals.getLoop().stop()


def onMQTTDisconnect(client, userdata, rc):
def onMQTTDisconnect(client, userdata, flags, reason_code, properties):
"""Callback invoke when we disconnect from MQTT broker"""
if rc != 0:
print(f"MQTT: unexpected disconnection error {rc}")
if reason_code != 0:
print(f"MQTT: unexpected disconnection error {reason_code}")
_globals = Globals.getInstance()
if _globals.getLoop() is not None:
_globals.getLoop().stop()


def onMQTTPublish(client, userdata, mid):
def onMQTTPublish(client, userdata, mid, reason_codes, properties):
"""Callback invoked when a message has completed transmission to the broker"""
pass

Expand Down Expand Up @@ -431,7 +431,7 @@ def initMQTT():
mqtt = _globals.getMQTT()
client_id = f'meshtastic2hass-{random.randint(0, 100)}'
try:
mqtt = mqttClient.Client(mqttClient.CallbackAPIVersion.VERSION1, client_id, True)
mqtt = mqttClient.Client(mqttClient.CallbackAPIVersion.VERSION2, client_id, True)
_globals.setMQTT(mqtt)
_globals.setTopicPrefix(args.mqtt_topic_prefix)
mqtt.on_message = onMQTTMessage
Expand Down

0 comments on commit 1a99f59

Please sign in to comment.