Repository navigation
Drop !remove'd keys from the MQTT discovery block - #2982
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
🟡 Changes recommended
Raw-block filtering can bypass inherited TLS settings and potentially expose MQTT credentials over plaintext.
1 open issue
What changed in this PR
This PR fixes MQTT discovery for package-based device configurations that use !remove, filtering removed settings before broker resolution.
Changes:
- Preserve
!removemarkers in tolerant YAML parsing. - Drop removed keys from raw and package-resolved MQTT blocks.
- Add regression tests for removed TLS and client-certificate settings.
| File | Description |
|---|---|
tests/test_mqtt_coordinator_extract.py |
Tests monitor creation after package MQTT settings are removed. |
esphome_device_builder/helpers/device_yaml/_tolerant_yaml.py |
Preserves !remove as ESPHome markers. |
esphome_device_builder/helpers/device_yaml/_mqtt_block.py |
Filters removal markers from MQTT extracts. |
Review effort: Balanced
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2982 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 300 300
Lines 26484 26499 +15
=======================================
+ Hits 26423 26438 +15
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 8e55418:
Skipped: reusing ESPHome Bot (@esphbot) review |
# Conflicts: # esphome_device_builder/helpers/device_yaml/_mqtt_block.py # tests/test_mqtt_coordinator_extract.py
|
Merged main (post #2965) in 9484710. ESPHome Bot (@esphbot) review |
|
Merged main to bring the branch up to date; no conflicts, and the PR's tests pass locally. ESPHome Bot (@esphbot) review |
|
|
ESPHome Bot (esphbot)
left a comment
There was a problem hiding this comment.
Tip
No blocking issues found — ready to merge.
PR Review — Drop !remove'd keys from the MQTT discovery blockMerge-ready. The one open item from the last review, the out-of-date PR description, is now fixed. No new findings. Strengths:
Needs attention:
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.
|
Updated the PR description to match the deep-load strip (the ESPHome Bot (@esphbot) review |
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?
Keys removed with
!removeare dropped from the merged config, so MQTT discovery (and every other reader) no longer sees a removed package key as set.load_device_yamlmerges packages with esphome'sresolve_packages, which leavesconfig_helpers.Removemarkers in place; esphome strips them later inresolve_extend_remove. A device removing a package's TLS settings therefore got "broker could not be resolved" and no monitor. In the same way, a removedclient_certificatestill counted as client-certificate auth._loading:load_device_yamlnow drops everykey: !removefrom the merged config at any depth (the dict-key half ofresolve_extend_remove).id: !remove xlist-item removals stay as markers foresphome config, and still count as deferred work inresolution_incomplete. This also fixesapi: !remove/mqtt: !remove/deep_sleep: !removeover a package reading as present._tolerant_yaml:!removeloads as esphome'sRemove(value)marker instead ofNone(its only other caller,yaml_declares_ota_old_key, checks for dicts only, so it is unaffected)._mqtt_block: a device file whose ownmqtt:block!removes a key is not resolved from that block alone. Such a block only overrides a package, so the broker comes from the merged block. Otherwise an inlinebroker:plus!removewould lose the package's port, TLS and login.Tests: one parametrized coordinator test covers a package's
port+certificate_authorityremoved, its client-certificate keys removed, and an inlinebroker:next to a!remove. Each case checks host, port, username and CA, and that no warning is logged. A loader test pins removed keys dropped at the top level and nested.test_resolution_incompletepins a dict-key removal as resolved and anid: !removelist item as deferred.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.