Repository navigation
Support paho-mqtt 1.x and 2.x in the MQTT discovery monitor - #2958
Conversation
|
ESPHome Bot (@esphbot) review |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
🟢 Approval recommended
The focused compatibility changes have supporting unit and integration coverage, with no unresolved findings.
No open issues 🎉
What changed in this PR
Adds paho-mqtt 1.x and 2.x compatibility to MQTT discovery without changing dependency ownership.
Changes:
- Selects callback API v2 when available and handles both callback formats.
- Adds compatibility tests and updates MQTT test clients.
- Adds a paho 2.1.0 CI leg and documents dual-version support.
| File | Description |
|---|---|
| tests/test_mqtt_monitor.py | Tests v2 construction and callback result handling. |
| tests/e2e/slow/mqtt/conftest.py | Supports both paho versions in test clients. |
| esphome_device_builder/controllers/_device_mqtt_monitor.py | Adapts client construction and callbacks. |
| docs/ARCHITECTURE.md | Documents dual-version compatibility. |
| .github/workflows/test.yml | Tests the ESPHome pin and paho 2.1.0. |
Review effort: Balanced
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
ESPHome Bot (@esphbot) review Applied in 5f7ee79: dropped the unused |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2958 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 300 300
Lines 26425 26429 +4
=======================================
+ Hits 26363 26367 +4
Misses 62 62
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Confirmed. |
PR Review — Support paho-mqtt 1.x and 2.x in the MQTT discovery monitorReady to merge. The one earlier finding is fixed, and I found nothing new. What the PR does well:
Prior finding:
Checklist
Automated review by Kōan (Claude) |
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
What does this implement/fix?
The MQTT discovery monitor now runs on both paho-mqtt 1.x and 2.x, so the dashboard keeps working whichever esphome release it is installed next to.
Mechanism
paho 2 with
CallbackAPIVersion.VERSION2passeson_connect(client, userdata, flags, reason_code, properties)andon_subscribe(client, userdata, mid, reason_codes, properties), where the codes areReasonCodeobjects: value 0 is success, values at or above 0x80 are failures, and a v3 CONNACK rc 4 arrives as 134 "Bad user name or password". paho 1 passes four arguments with plain ints. The monitor's two callbacks take*_for the extra argument and compare through_code_value, which reads.valuewhen present and the int otherwise. Every other call the monitor makes (tls_set_context,tls_insecure_set,username_pw_set,connect,loop_start,loop_stop,disconnect,publish().rc) is unchanged between the majors.Constructing without a
CallbackAPIVersionon paho 2 still works but raises aDeprecationWarningon every session and stays on the v1 path that paho plans to remove, which is why the switch is explicit.The
clientlocal is typedAnyon purpose: paho 2 shipspy.typed, and itssubscribeandpublishsignatures do not structurally match the narrowSubscribeClientandPublishClientprotocols, so a typed local would fail mypy the day the pin moves.Verification
pytest tests/test_mqtt_monitor.py tests/e2e/slow/mqtt -W error::DeprecationWarningagainst a real mosquitto: 147 passed on paho 1.6.1 (the project venv) and 147 passed on paho 2.1.0 (a scratch venv built from the same constraints with paho overridden).mypyon the monitor and coordinator passes in both venvs, including against paho 2's typed surface.CallbackAPIVersionbearing stand-in: the client is built with VERSION2, a failing CONNACK reason code rejects by name, a SUBACK reason code at or above 0x80 fails the session, and_code_valueis pinned for ints and reason codes. The existing paho 1 shaped tests are untouched.lambda c, *_:foron_connect, so they run on either major.Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesFrontend coordination
Checklist
ruff,codespell, yaml/json/python checks).tests/where applicable.components.index.json/definitions/components/*.jsonhave not been hand-edited (regenerate viascript/sync_components.pyif a sync is needed).docs/ARCHITECTURE.mdand/ordocs/API.md.