Commit e3fc002
committed
driver/resource: mqtt: use callback API v2, bump paho-mqtt>=2.0.0
labgrid's "mqtt" and "dev" extras require paho-mqtt>=1.5.1. With
paho-mqtt 2.0.0 [1] released on 2024-02-10, breaking changes were
introduced [2]. This was first detected by the scheduled CI jobs via
pylint:
************* Module labgrid.resource.mqtt
labgrid/resource/mqtt.py:20:17: E1120: No value for argument 'callback_api_version' in constructor call (no-value-for-parameter)
************* Module labgrid.driver.mqtt
labgrid/driver/mqtt.py:30:23: E1120: No value for argument 'callback_api_version' in constructor call (no-value-for-parameter)
When using 'labgrid-client pw get' with a TasmotaPowerPort resource,
the errors looks like this:
DEBUG root: Starting session with "ws://labgrid:20408/ws", realm: "realm1"
Exception ignored in: <function Client.__del__ at 0x7fd594564a40>
Traceback (most recent call last):
File "/path/to/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 874, in __del__
self._reset_sockets()
File "/path/to/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1133, in _reset_sockets
self._sock_close()
File "/path/to/venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1119, in _sock_close
if not self._sock:
^^^^^^^^^^
AttributeError: 'Client' object has no attribute '_sock'
Traceback (most recent call last):
File "/path/to/labgrid/labgrid/factory.py", line 124, in make_resource
r = cls(target, name, **args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "<attrs generated init labgrid.resource.mqtt.TasmotaPowerPort>", line 19, in __init__
self.__attrs_post_init__()
File "/path/to/labgrid/labgrid/resource/mqtt.py", line 61, in __attrs_post_init__
super().__attrs_post_init__()
File "/path/to/labgrid/labgrid/resource/common.py", line 157, in __attrs_post_init__
self.manager._add_resource(self)
File "/path/to/labgrid/labgrid/resource/common.py", line 133, in _add_resource
self.on_resource_added(resource)
File "/path/to/labgrid/labgrid/resource/mqtt.py", line 29, in on_resource_added
self._clients[host] = self._create_mqtt_connection(host)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/labgrid/labgrid/resource/mqtt.py", line 20, in _create_mqtt_connection
client = mqtt.Client()
^^^^^^^^^^^^^
TypeError: Client.__init__() missing 1 required positional argument: 'callback_api_version'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/path/to/labgrid/labgrid/remote/client.py", line 1892, in main
args.func(session)
File "/path/to/labgrid/labgrid/remote/client.py", line 726, in power
target = self._get_target(place)
^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/labgrid/labgrid/remote/client.py", line 687, in _get_target
RemotePlace(target, name=place.name)
File "<attrs generated init labgrid.resource.remote.RemotePlace>", line 11, in __init__
self.__attrs_post_init__()
File "/path/to/labgrid/labgrid/resource/remote.py", line 101, in __attrs_post_init__
super().__attrs_post_init__()
File "/path/to/labgrid/labgrid/resource/common.py", line 157, in __attrs_post_init__
self.manager._add_resource(self)
File "/path/to/labgrid/labgrid/resource/common.py", line 133, in _add_resource
self.on_resource_added(resource)
File "/path/to/labgrid/labgrid/resource/remote.py", line 53, in on_resource_added
new = target_factory.make_resource(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/labgrid/labgrid/factory.py", line 126, in make_resource
raise InvalidConfigError(
labgrid.exceptions.InvalidConfigError: failed to create TasmotaPowerPort for target 'Target(name='test', env=None)' using {'host': 'mqtt', 'status_topic': 'stat/03374/POWER', 'power_topic': 'cmnd/03374/POWER', 'avail_topic': 'tele/03374/LWT'}
This is likely caused by an error in the environment configuration or invalid
resource information provided by the coordinator.
To fix this, use paho-mqtt's callback API v2 and migrate the on_connect()
callback. Require paho-mqtt>=2.0.0 from now on.
[1] https://github.com/eclipse/paho.mqtt.python/releases/tag/v2.0.0
[2] https://github.com/eclipse/paho.mqtt.python/blob/master/docs/migrations.rst#change-between-version-1x-and-20
Signed-off-by: Bastian Krause <bst@pengutronix.de>1 parent 00f466c commit e3fc002
3 files changed
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
0 commit comments