ironsheep/RPi-Reporter-MQTT2HA-Daemon

RPi-Reporter doesn't work with paho-mqtt 2.0.0+

ghTravis opened this issue · 2 comments

Checklist:

  • [ x ] I updated to the latest version available
  • [ x ] I checked that my MQTT broker is otherwise working

Release with the issue: latest

Last working release (if known): paho-mqtt==1.6.1

Hardware, Operating System, Python version: raspbian latest, python3.9

Description of problem:

RPi-Reporter fails to start with error:

Feb 13 08:13:28 atlantis systemd[1]: Starting RPi Reporter MQTT Client/Daemon...
Feb 13 08:13:29 atlantis python[1791553]: Exception ignored in: <function Client.__del__ at 0x7f91d12940>
Feb 13 08:13:29 atlantis python[1791553]: Traceback (most recent call last):
Feb 13 08:13:29 atlantis python[1791553]:   File "/opt/RPi-Reporter-MQTT2HA-Daemon/lib/python3.9/site-packages/paho/mqtt/client.py", line 874, in __del__
Feb 13 08:13:29 atlantis python[1791553]:     self._reset_sockets()
Feb 13 08:13:29 atlantis python[1791553]:   File "/opt/RPi-Reporter-MQTT2HA-Daemon/lib/python3.9/site-packages/paho/mqtt/client.py", line 1133, in _reset_sockets
Feb 13 08:13:29 atlantis python[1791553]:     self._sock_close()
Feb 13 08:13:29 atlantis python[1791553]:   File "/opt/RPi-Reporter-MQTT2HA-Daemon/lib/python3.9/site-packages/paho/mqtt/client.py", line 1119, in _sock_close
Feb 13 08:13:29 atlantis python[1791553]:     if not self._sock:
Feb 13 08:13:29 atlantis python[1791553]: AttributeError: 'Client' object has no attribute '_sock'
Feb 13 08:13:29 atlantis python[1791553]: Traceback (most recent call last):
Feb 13 08:13:29 atlantis python[1791553]:   File "/opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py", line 1286, in <module>
Feb 13 08:13:29 atlantis python[1791553]:     mqtt_client = mqtt.Client()
Feb 13 08:13:29 atlantis python[1791553]: TypeError: __init__() missing 1 required positional argument: 'callback_api_version'

This is due to paho-mqtt just releasing 2.0.0 which has a breaking change listed here.

The last known version of paho-mqtt that works is 1.6.1 so maybe the requirements.txt can be updated for now to pin at that version, or perhaps someone could make a PR for the updated 2.0.0 version

paho-mqtt==1.6.1 in requirements.txt works indeed as temporary workaround

Implementing a quick fix (that will work until paho-mqtt v3 is released and VERSION1 is dropped) is easy:

# ensure backward compatibility with older versions of paho-mqtt (<=2.0.0)
# ToDo: Need to update to VERSION2 at some point
try:
    mqtt_client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION1)
except AttributeError:
    mqtt_client = mqtt.Client()