Resolve esphome meta substitutions from packages and !include#932
Merged
Conversation
The dashboard's friendly_name / area / comment readers only looked at substitutions inline in the device YAML, so a config that kept shared values in a packages: file (or pulled them in via !include) rendered the raw $token on the device card. Feed the merged substitutions: map off the resolved config back into parse_esphome_meta as an extras fallback. File-local entries still win on key conflicts, mirroring esphome's do_packages_pass precedence. Fixes #917
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes ESPHome $token substitutions in device card metadata (friendly_name / area / comment) when the substitutions are defined via packages: or !include, by letting the meta parser resolve against the merged substitutions map from the already-resolved config.
Changes:
- Extend
parse_esphome_meta()with anextra_substitutionsfallback map and merge it with file-local substitutions using ESPHome-like precedence (local overrides package). - Thread merged substitutions from
load_device_yaml()intoload_device_from_storage()so dashboard metadata resolution matches what the compiler sees. - Add unit + integration tests covering extras-only resolution, local override precedence, and “merge-not-swap” behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
esphome_device_builder/helpers/device_yaml.py |
Adds extra_substitutions support to meta parsing and feeds merged substitutions from resolved config into metadata extraction. |
tests/test_device_yaml.py |
Adds regression/unit/integration tests ensuring substitutions resolve correctly with packages/includes and that precedence matches ESPHome behavior. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #932 +/- ##
=======================================
Coverage 99.24% 99.24%
=======================================
Files 191 191
Lines 14200 14210 +10
=======================================
+ Hits 14093 14103 +10
Misses 107 107
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this implement/fix?
friendly_name/area/commenton the device card stayedstuck on raw
$tokentext whenever the substitution came from apackages:block or!includefile — the meta reader only lookedat substitutions inline in the device YAML.
Now feed the merged
substitutions:map off the resolved config(which already runs
do_packages_pass+merge_packagesupstream)into
parse_esphome_metaas an extras fallback. File-localentries still win on key conflicts, matching esphome's package
merge precedence.
extra_substitutionsparam toparse_esphome_metaso themeta reader can resolve
$tokens defined outside the file.load_device_from_storageextracts the mergedsubstitutions:off
resolved_configand threads them through.override case, and the merge-not-swap case.
Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesFrontend coordination
Checklist
ruff,codespell, yaml/json/python checks).tests/where applicable.components.jsonhas not been hand-edited (regenerate viascript/sync_components.pyif a sync is needed).docs/ARCHITECTURE.mdand/ordocs/API.md.