Skip to content

Derive a device's board from its merged config - #3035

Merged
J. Nick Koston (bdraco) merged 3 commits into
mainfrom
board-from-merged-config
Nov 6, 2026
Merged

J. Nick Koston (bdraco) merged 3 commits into
mainfrom
board-from-merged-config

Conversation

@bdraco

Copy link
Copy Markdown
Member

What does this implement/fix?

A device's board was worked out from a raw text scan of its YAML, so a chip or board set inside packages: or behind a substitution was invisible and those devices showed no board; it is now derived at device load from the merged config, so they show the board they actually compile for.

# before: metadata resolver, re-reads the file and scans raw text
platform, pio_board, variant = parse_platform_from_yaml(yaml_content)

# after: device load, from the merged config it already holds
board, variant = resolve_board_fields(
    config, yaml_content, target_platform, extra_substitutions, storage_variant
)
  • An esp32 config with no variant: takes its chip from resolve_esp32_variant, the rule the logger interface already uses, so both agree on the chip.
  • The resolver no longer reads each YAML a second time; a user picked board is still kept as is.
  • Follows Stop guessing a board when the ESP32 variant is unknown #3030, which stopped the lookup from guessing a C6 when the chip was unknown.
Live check with the issue's layouts

Dev backend pointed at a scratch config dir, board_id from subscribe_events initial state:

config main this branch
esp32: framework only, variant in a package empty esp32-generic-s3-bluetooth-proxy
whole esp32: block in a package empty esp32-generic-s3-bluetooth-proxy
board: lolin_s3_mini in a package empty lolin_s3_mini

The startup shallow scan has no merged config yet, so these show no board until the deep pass fills it in; same as mcu today. Which S3 entry wins is catalog order (the bluetooth proxy manifests are marked generic); that is separate from this change.

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-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.index.json / definitions/components/*.json have 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 board id was derived from a raw text scan of the YAML, so a chip or
board set inside packages: or behind a substitution was never seen.
Derive it at device load instead, where the merged config is already in
hand, and take the esp32 chip from resolve_esp32_variant so the board
and the logger interface agree on it.
@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@github-actions github-actions Bot added the bugfix Bug fix label Nov 6, 2026
@bdraco
J. Nick Koston (bdraco) marked this pull request as ready for review November 6, 2026 01:40
Copilot AI balanced review requested due to automatic review settings November 6, 2026 01:40
@codspeed

codspeed Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 28 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing board-from-merged-config (dd65b71) with main (8a3af7b)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the changes that derive board identification from merged configuration.

No open issues 🎉

What changed in this PR

Moves board identification into device loading, where merged configuration exposes boards and chips defined through packages or substitutions. This follows #3030 and addresses #2987 while preserving explicit user board selections.

Changes:

  • Derives board metadata from merged configuration and reuses ESP32 variant resolution.
  • Passes catalog lookup through the scanner, eliminating the metadata resolver’s extra YAML read.
  • Adds package and substitution coverage and updates lookup, metadata, and migration tests.
File Description
tests/​test_device_board_id.py Adds merged-config, substitution, and user-selection coverage.
tests/​controllers/​devices/​test_metadata_resolver.py Updates expectations for user-picked versus derived boards.
tests/​controllers/​devices/​test_derive_board_id.py Tests catalog lookup independently of YAML reading.
tests/​controllers/​devices/​test_board_id_user_set_migration.py Checks migrated board IDs through device loading.
esphome_device_builder/​helpers/​device_yaml/​_loading.py Derives unset board IDs during device loading.
esphome_device_builder/​helpers/​device_yaml/​_chip.py Adds board resolution and shares platform-field extraction.
esphome_device_builder/​helpers/​device_yaml/​__init__.py Exports the board-derivation callback type.
esphome_device_builder/​controllers/​devices/​metadata.py Keeps user picks and separates catalog lookup from YAML reading.
esphome_device_builder/​controllers/​devices/​controller.py Supplies board lookup to the scanner.
esphome_device_builder/​controllers/​devices/​__init__.py Updates the documented helper name.
esphome_device_builder/​controllers/​_device_scanner.py Threads board derivation into device loads.

Review effort: Balanced

@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.77%. Comparing base (8a3af7b) to head (dd65b71).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3035   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files         300      300           
  Lines       26556    26565    +9     
=======================================
+ Hits        26495    26504    +9     
  Misses         61       61           
Flag Coverage Δ
py3.12 99.73% <100.00%> (+<0.01%) ⬆️
py3.14 99.62% <100.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...home_device_builder/controllers/_device_scanner.py 100.00% <100.00%> (ø)
...ome_device_builder/controllers/devices/__init__.py 100.00% <ø> (ø)
...e_device_builder/controllers/devices/controller.py 100.00% <ø> (ø)
...ome_device_builder/controllers/devices/metadata.py 100.00% <100.00%> (ø)
...ome_device_builder/helpers/device_yaml/__init__.py 100.00% <100.00%> (ø)
...sphome_device_builder/helpers/device_yaml/_chip.py 100.00% <100.00%> (ø)
...ome_device_builder/helpers/device_yaml/_loading.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@esphbot

ESPHome Bot (esphbot) commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Previous review — superseded by a newer review below.

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tip

No blocking issues found — ready to merge.

A scanner built without it would silently load every device with no
board. Also pin that the last compile's chip outranks the board table.
@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@esphbot

Copy link
Copy Markdown
Contributor

PR Review — Derive a device's board from its merged config

Ready to merge. The earlier wiring concern is fixed, and only one non-blocking note is left.

What the PR does well:

  • The board is now worked out at device load, from the merged config, so a board or chip set in packages: or through a substitution shows up ([Bug] Device Builder reports incorrect ESP32 variant when hardware config comes from packages #2987).
  • The metadata resolver no longer reads each YAML a second time.
  • The esp32 chip now comes from resolve_esp32_variant, the same rule the logger interface uses, so the two can't disagree.
  • _platform_block_values replaces _chip_fields and is shared with resolve_chip_mcu. The rp2 family special case moved to the caller with no change in behaviour.
  • The shallow scan still falls back to the raw text, so plain configs keep getting a board on the first pass.
  • Commit dd65b71 makes derive_board_id a required argument on DeviceScanner, which resolves the earlier concern that forgetting to wire it would fail silently. The scanner is the only caller of load_device_from_storage, and it always passes the deriver.
  • target_platform is normalized before it reaches _derive_board_id (_loading.py:294).
  • test_device_board_id.py checks packages, substitutions, the last-compile chip and user picks against the real catalog.

Remaining note:

  • The chip from the last compile still beats an edited board: that isn't in the catalog. This is intentional to match the logger rule, and a test now pins it (non-blocking).

✅ Resolved since last review (1)

Previously-flagged issues verified fixed
  • esphome_device_builder/controllers/_device_scanner.py:314 Optional derive_board_id makes a missing wiring fail silently


Checklist

  • No hardcoded secrets
  • All callers of changed contracts updated (_resolve_device_metadata, DeviceScanner, load_device_from_storage)
  • User-set board_id still preserved (is True guard kept)
  • Wiring is explicit and hard to omit (scanner arg now required)
  • Edge cases: missing catalog, shallow scan, failed deep parse
  • Variant precedence intentional and test-pinned
  • Tests cover new behaviour

Automated review by Kōan (Claude) HEAD=dd65b71 28s

@esphbot ESPHome Bot (esphbot) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tip

No blocking issues found — ready to merge.

@bdraco
J. Nick Koston (bdraco) merged commit 8aa831f into main Nov 6, 2026
27 checks passed
@bdraco
J. Nick Koston (bdraco) deleted the board-from-merged-config branch November 6, 2026 02:00
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Device Builder reports incorrect ESP32 variant when hardware config comes from packages

3 participants