Repository navigation
Skip MQTT brokers whose login holds an unresolved substitution - #2981
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The focused shared guard implements the stated token policy with regression coverage for both extraction paths and no blocking issues identified.
No open issues 🎉
What changed in this PR
This PR extends MQTT discovery’s unresolved-substitution guard to usernames and passwords, preventing repeated rejected logins with literal substitution tokens.
Changes:
- Skip brokers with unresolved
${…}or whole-value$namecredentials. - Preserve passwords that merely contain dollar signs.
- Add regression coverage for inline credentials, package-sourced credentials, and coordinator behavior.
| File | Description |
|---|---|
tests/test_mqtt_monitor.py |
Tests unresolved login rejection and dollar-containing password preservation. |
tests/test_mqtt_coordinator_extract.py |
Tests consistent credential handling for package-sourced MQTT configuration. |
esphome_device_builder/controllers/_device_mqtt_coordinator.py |
Adds credential-token detection to shared broker extraction. |
Review effort: Balanced
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2981 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 300 300
Lines 26480 26484 +4
=======================================
+ Hits 26419 26423 +4
Misses 61 61
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
|
Simplify pass in 21fa4a1:
Skipped: refusing a declared login whose secret resolves to empty. An empty password can be a legitimate config, so that would change behavior. Note: #2965 turns the host check in this same function into a per-field loop. Whichever PR lands second should fold ESPHome Bot (@esphbot) review |
# Conflicts: # esphome_device_builder/controllers/_device_mqtt_coordinator.py # tests/test_mqtt_coordinator_extract.py # tests/test_mqtt_monitor.py
|
Merged main (post #2965) in c4110a9. The login check now rides #2965's per-field loop: ESPHome Bot (@esphbot) review |
PR Review — Skip MQTT brokers whose login holds an unresolved substitutionReady to merge. The login guard is correct after the rebase onto #2965, and nothing is outstanding. What the PR does well:
No outstanding issues. 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.
Rebase verified. Login fields now go through the shared loop ( |
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?
MQTT discovery skips a broker whose
usernameorpasswordstill holds an unresolved substitution, the same way it already does forbroker:(#1643). Before, the monitor logged in with the literal token and the broker rejected it every 5 s, forever.A resolved block can't tell a
!secretvalue from a literal (esphome's loader has already inlined the secret on the package path), so the check is on the token shape: the value contains${, or is entirely one$name. A real password that merely contains$(pa$swordfrom a secret, a literalpa$$word) still logs in on both the inline and the package path, as esphome compiles it. Known gap: a password that is exactly$wordis treated as a token.Tests: unresolved
${x}/$x/ Jinja-style logins yield no broker; passwords containing$are kept; a package-sourced login is judged like an inline one (test_seed_login_matches_the_main_path); the coordinator test for an unresolved host also covers the username.Overlaps with #2965 in
_broker_from_blockandtests/test_mqtt_monitor.py; whichever lands second needs a small rebase. Happy to rebase this one.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.