Skip to content

Resolve esphome meta substitutions from packages and !include#932

Merged
marcelveldt merged 1 commit into
mainfrom
fix/issue-917-package-substitutions
May 21, 2026
Merged

Resolve esphome meta substitutions from packages and !include#932
marcelveldt merged 1 commit into
mainfrom
fix/issue-917-package-substitutions

Conversation

@marcelveldt
Copy link
Copy Markdown
Contributor

What does this implement/fix?

friendly_name / area / comment on the device card stayed
stuck on raw $token text whenever the substitution came from a
packages: block or !include file — the meta reader only looked
at substitutions inline in the device YAML.

Now feed the merged substitutions: map off the resolved config
(which already runs do_packages_pass + merge_packages upstream)
into parse_esphome_meta as an extras fallback. File-local
entries still win on key conflicts, matching esphome's package
merge precedence.

  • Add extra_substitutions param to parse_esphome_meta so the
    meta reader can resolve $tokens defined outside the file.
  • load_device_from_storage extracts the merged substitutions:
    off resolved_config and threads them through.
  • Unit + integration tests covering the package case, the local
    override case, and the merge-not-swap case.

Related issue or feature (if applicable):

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — docs
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Frontend coordination

  • No frontend change needed
  • Companion frontend PR: esphome/device-builder-dashboard-frontend#

Checklist

  • The code change is tested and works locally.
  • Pre-commit hooks pass (ruff, codespell, yaml/json/python checks).
  • Tests have been added or updated under tests/ where applicable.
  • components.json has not been hand-edited (regenerate via script/sync_components.py if a sync is needed).
  • Architecture-level changes are reflected in docs/ARCHITECTURE.md and/or docs/API.md.

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
Copilot AI review requested due to automatic review settings May 21, 2026 21:38
@github-actions github-actions Bot added the bugfix Bug fix label May 21, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 21, 2026

Merging this PR will not alter performance

✅ 25 untouched benchmarks


Comparing fix/issue-917-package-substitutions (d79d5dd) with main (332c3f8)

Open in CodSpeed

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 an extra_substitutions fallback map and merge it with file-local substitutions using ESPHome-like precedence (local overrides package).
  • Thread merged substitutions from load_device_yaml() into load_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-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.24%. Comparing base (332c3f8) to head (d79d5dd).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #932   +/-   ##
=======================================
  Coverage   99.24%   99.24%           
=======================================
  Files         191      191           
  Lines       14200    14210   +10     
=======================================
+ Hits        14093    14103   +10     
  Misses        107      107           
Flag Coverage Δ
py3.12 99.19% <100.00%> (+<0.01%) ⬆️
py3.14 99.24% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
esphome_device_builder/helpers/device_yaml.py 96.51% <100.00%> (+0.10%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcelveldt marcelveldt merged commit 257bc01 into main May 21, 2026
23 of 24 checks passed
@marcelveldt marcelveldt deleted the fix/issue-917-package-substitutions branch May 21, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Device name doesn’t do substitutions

3 participants