Skip to content

Add Seeed XIAO 1.47" IPS Touch Display (nRF52840) board with demo overlay - #2971

Draft
tomaszduda23 wants to merge 19 commits into
esphome:mainfrom
tomaszduda23:display
Draft

tomaszduda23 wants to merge 19 commits into
esphome:mainfrom
tomaszduda23:display

Conversation

@tomaszduda23

Copy link
Copy Markdown
Contributor

What does this implement/fix?

Adds the Seeed XIAO 1.47" IPS Touch Display (nRF52840) board. New devices start from a Zigbee demo: an LVGL spirit level driven by the IMU, button indicators, an RGB LED and a backlight that boots at full brightness.

xiao-147-demo-screen
  • Board hardware (SPI, display, backlight, I2C + LSM6DS, LEDs, buttons) is installed as default_components and offered on the Recommended tab, with a "Display (full setup)" bundle. The I2C and SPI buses are named i2c_bus / spi_bus because they're shared with the touch controller and the XIAO header. Pins use nRF52 P<port>.<pin> notation.
  • New: board demo overlay. A board's demo.yaml is merged on top of the generated config at create time. - id: !extend <id> attaches automations to default components, so the demo carries no pins. Conflicting keys fail loudly.
  • Catalog sync fixes (regenerated against 2026.10.0):
    • nrf52 now provides zephyr, so adding output.zephyr_pwm no longer asks for a zephyr component that doesn't exist.
    • The mipi displays' transform (disabled or a mirror/swap mapping) syncs as a YAML-only unknown field instead of a one-option select that rejected the mapping.

Requires:

Types of changes

  • New feature (non-breaking change which adds functionality) — new-feature

Frontend coordination

  • No frontend change needed

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 (regenerated via script/sync_components.py).
  • Architecture-level changes are reflected in docs (definitions/README.md).

🤖 Generated with Claude Code

Boards can now ship a complete starter config as boards/<id>/demo.yaml.
The sync bakes it into the board body (demo_yaml) and devices/create
writes it, prefixed with name/friendly_name substitutions, instead of
the generated template.

The new board ships a Zigbee demo (LVGL spirit level driven by the
LSM6DS IMU, button indicators, RGB LED, backlight number) plus featured
components and a display bundle for its onboard hardware.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
The board's hardware (SPI, display, backlight PWM, I2C, IMU, LEDs) now
installs through default_components; demo.yaml carries only the demo
behaviour and merges on top: absent blocks append, list domains gain
items, mappings gain keys, and conflicting keys or shapes raise.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
USR1/USR2 become default components like the LEDs, and the demo
overlay adds on_press/on_release to them with ESPHome's
`- id: !extend <id>` item form, so demo.yaml carries no pins. The
overlay now merges in the create path, where defaults are resolved.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
The template number and the zephyr_pwm output share HARDWARE setup
priority, so the number's boot publish can reach the output before it
is ready and leave the panel dark. An on_boot hook at priority -100
re-publishes the restored value (100 % on first boot).

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
The generated main.cpp registers the zephyr_pwm output before the
template number and setup sorting is stable, so the number's restored
value (100 % on first boot) already reaches a ready output.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
Drop restore_value on the backlight number so initial_value (100 %)
applies on every boot instead of a previously stored low step.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
The catalog types mipi_spi's transform as the string `disabled` only
(the mapping form comes from a cv.Any the schema bundle loses), so the
Recommended add rejected the mirror preset as "Not a valid option".
The mapping now rides the default_components override, which renders
on the backend; the create path test pins it against the real catalog.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
nrf52 AUTO_LOADs zephyr, which output.zephyr_pwm depends on but no
catalog entry represents, so the add form asked the user to "Add
zephyr" with nothing to add. The sync now advertises such auto-loaded
deps in the platform entry's provides (today: nrf52 -> zephyr), which
the frontend already honours as satisfying the dependency.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
Re-synced against esphome 2026.10.0; the only change is the nrf52
entry gaining provides: [zephyr]. The auto-load pass also no longer
skips deps that have their own catalog entry: a platform block
satisfies whatever it auto-loads either way.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
The schema bundle dumps cv.Any(one_of("disabled"), Schema) as an enum
carrying a schema; the sync kept only the enum, so a mirror/swap
mapping preset failed the add form's option check. Such fields
(transform on mipi_spi / mipi_rgb / mipi_dsi) now sync as `unknown`,
the existing YAML-only union type, and the XIAO display's mirror moves
back into its locked Recommended preset.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
The I2C bus (D4/D5) carries the IMU, the touch controller and the
header, and the SPI bus (D8/D10) is the header SPI the display sits on,
so imu_i2c / lcd_spi become i2c_bus / spi_bus. Their pins are marked
exposed and shared, and the unused header MISO (D9, P1.14) is listed
as free.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
Presets now use the board's P<port>.<pin> labels (P1.13, not 45), the
spelling the pin picker writes, so generated YAML is consistent with
pins the user adds. The sync still resolves them to locked_pins.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
The onboard RGB LED (P0.26 / P0.30 / P0.06, active low) is part of the
XIAO nRF52840 itself, so xiao_ble gets the same three LED switches the
display board recommends, plus an "RGB LED (full setup)" bundle on both.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
xiao_ble installs its three LED switches by default and ships a
demo.yaml that cycles them red, green, blue from boot. The
"RGB LED (full setup)" bundle is dropped from both XIAO boards.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
Three intervals toggle the red, green and blue LEDs every 1 s, 2 s and
4 s, stepping through all eight color combinations without a script.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
Restores xiao_ble to upstream's manifest; its RGB LED featured
components and LED demo continue on the xiao-nrf52840-rgb-led branch.

Claude-Session: https://claude.ai/code/session_01W2jQ8Gespoc8q1aqGBiNgK
@tomaszduda23
tomaszduda23 marked this pull request as draft October 25, 2026 10:48
@github-actions github-actions Bot added the new-feature New feature label Oct 25, 2026
@tomaszduda23

Copy link
Copy Markdown
Contributor Author

ESPHome Bot (@esphbot) review

@codspeed

codspeed Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 28 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing tomaszduda23:display (8dc9c3c) with main (1adedf4)

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. ↩

@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (1adedf4) to head (8dc9c3c).
⚠️ Report is 77 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main    #2971    +/-   ##
========================================
  Coverage   99.76%   99.76%            
========================================
  Files         300      300            
  Lines       26430    26553   +123     
========================================
+ Hits        26368    26491   +123     
  Misses         62       62            
Flag Coverage Δ
py3.12 99.73% <100.00%> (+<0.01%) ⬆️
py3.14 99.61% <100.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...vice_builder/controllers/devices/mutations_yaml.py 100.00% <100.00%> (ø)
esphome_device_builder/definitions/__init__.py 100.00% <100.00%> (ø)
esphome_device_builder/helpers/yaml/__init__.py 100.00% <100.00%> (ø)
esphome_device_builder/helpers/yaml/component.py 99.43% <100.00%> (+0.25%) ⬆️
esphome_device_builder/models/boards.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 Oct 25, 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.

Drop the overlay merge's unreachable splice fallback; test extending a
final item without a trailing newline, a callable platform AUTO_LOAD and
the enum-or-mapping union conversion.
Add mapping keys at the block's child indent instead of a nested list's
dash column, append body-less blocks the template lacks, refuse repeated
or inline-valued top-level overlay keys and malformed !extend items,
accept a comment on the !extend line, and surface merge conflicts on
create as INTERNAL_ERROR. The sync now fails on a callable platform
AUTO_LOAD instead of silently skipping it.
@esphbot

ESPHome Bot (esphbot) commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Review — Add Seeed XIAO 1.47" IPS Touch Display (nRF52840) board with demo overlay

Ready to merge. All findings from the previous round are fixed. Three small, non-blocking issues remain.

What's fixed and done well:

  • Mapping merge: keys now go in at the base block's child indent through _insert_lines. They no longer borrow the list splicer, and the nested-list case has a test.
  • Bare blocks: a body-less block the base lacks (captive_portal:) is now appended before the empty-body skip runs.
  • Block splitting: _overlay_blocks now splits on every column-0 line and refuses inline values and repeated keys.
  • !extend parsing: a trailing comment on the !extend line now matches. Any other !extend form raises a clear error instead of passing through.
  • Error mapping: merge ValueErrors are wrapped as INTERNAL_ERROR naming the board, and a test checks that no file is written.
  • Sync script: a callable AUTO_LOAD now fails the sync loudly, and the docstring is the one-line contract.
  • Coverage: test_shipped_demos_merge_through_create runs every shipped demo through the real create path.

Remaining suggestions:

  • The BoardCatalogEntry.demo_yaml comment still says the demo replaces the defaults; it is merged on top.
  • _insert_lines cuts lines indented less than src, so a column-0 comment inside a block can turn into YAML content.
  • Comments next to !extend items are dropped or attached to the wrong item.

✅ Resolved since last review (5)

Previously-flagged issues verified fixed
  • esphome_device_builder/helpers/yaml/component.py:121 Mapping merge borrows the list splicer, which picks up nested dash indents
  • esphome_device_builder/helpers/yaml/component.py:106 Empty-body overlay blocks are dropped without notice
  • esphome_device_builder/helpers/yaml/component.py:581 Overlay block splitting misses inline-value and repeated top-level keys
  • esphome_device_builder/helpers/yaml/component.py:32 A trailing comment on the !extend line leaks !extend into the output
  • esphome_device_builder/controllers/devices/mutations_yaml.py:134 Merge ValueError reaches the WS layer as a raw exception

🟢 Suggestions

1. `_insert_lines` cuts lines indented less than `src`, such as a column-0 comment inside a block
esphome_device_builder/helpers/yaml/component.py:687-694

_insert_lines re-indents each non-blank line as indent + line[len(src):]. It assumes every line starts with the src prefix, and nothing checks that.

How it breaks: _overlay_blocks only trims column-0 comments at the end of a block. A column-0 comment in the middle of a block stays in the body. Say a demo has # --- USR2 --- at column 0 between two - id: !extend items, or between mapping keys. With src = " ", "# --- USR2 ---"[4:] becomes "- USR2 ---". That turns the comment into a YAML list item, or into a stray scalar, under the extended item. The result fails strict validation with a confusing message, or changes the config's structure.

The shipped demo indents all of its comments, so nothing breaks today. This is the same "silent corruption vs loud refusal" gap the earlier rounds closed for headers.

Fix: re-indent comment lines without slicing, e.g. indent + line.lstrip() when line.lstrip().startswith("#"). Raise ValueError when a content line doesn't start with src. Add a test with a column-0 comment inside an !extend item.

moved = [indent + line[len(src) :] if line.strip() else line for line in extra]
2. Comments above an `!extend` item are dropped or attached to the wrong item
esphome_device_builder/helpers/yaml/component.py:608-620

Two related problems with comments in the extend path:

  • _apply_extensions takes extra = item[item.index(dash_line) + 1:]. Any lines before the dash line in an item group are thrown away without notice.
  • _split_list_items only starts a new group at a dash line. An indented comment written above item N+1 therefore lands at the end of item N. If item N is an !extend, that comment gets spliced into item N's target component instead of staying near item N+1.

This doesn't break anything functionally. It does mean demo authors' annotations end up in the wrong place in the user's config. That matters here because the demo is meant to be read and edited, which is why it carries comments like "Direction (use -x to reverse)".

Possible fix: when splitting, move the trailing comment lines of a group into the next group, and keep any pre-dash lines in the spliced output.

    blocks: list[tuple[str, list[str], list[str]]] = []
    previous_end = 0
    for pos, (key, start) in enumerate(headers):
        end = headers[pos + 1][1] if pos + 1 < len(headers) else len(lines)
        content_end = trim_trailing_gap(lines, start, end)
        comments = [line for line in lines[previous_end:start] if line.strip()]
        blocks.append((key, comments, lines[start + 1 : content_end]))
        previous_end = content_end
    return blocks


def _child_keys(lines: list[str], header_idx: int = 0, end_idx: int | None = None) -> set[str]:
    """Keys of a mapping block's direct children, lines ``(header_idx, end_idx)``."""

Checklist

  • No hardcoded secrets
  • Fail-loud on malformed overlay — suggestion #1
  • Correct YAML structure produced by merge
  • Errors surfaced with typed error codes
  • Comments and docs match behaviour — suggestion #2
  • Generated catalog files not hand-edited
  • Tests cover new behaviour
  • File stays under the 800-line soft cap
ℹ️ Triage summary

1 pre-existing finding(s) on unchanged code suppressed (freeze).


Silent Failure Analysis

🟡 **3. MEDIUM** — guard silently disabled
esphome_device_builder/helpers/yaml/component.py:620-628

Risk: _child_keys takes the child indent from the first non-blank line, and that line can be a comment. If the comment sits at a different indent (a column-0 # note right under nrf52: passes opens_top_level_block and trim_trailing_gap keeps it), no real key matches, the set comes back empty, and the 'repeats ' check passes. The merge then writes duplicate keys, such as a second board:, instead of raising ValueError.

body = lines[header_idx + 1 : len(lines) if end_idx is None else end_idx]
indent = next((leading_ws(line) for line in body if line.strip()), "")
for line in body:
    if leading_ws(line) == indent and (match := _CHILD_KEY_RE.match(line.strip())):
        keys.add(match.group(1))

Fix: Skip comment lines (line.lstrip().startswith('#')) when working out the indent in _child_keys, and do the same for the child/src lookups in merge_yaml_overlay and _extend_item.

🟡 **4. MEDIUM** — mis-derived indent corrupts output silently
esphome_device_builder/helpers/yaml/component.py:129-131

Risk: If the first non-blank overlay line is a comment indented differently from the real keys, src is wrong. line[len(src):] then cuts real characters off the content lines or leaves them at the wrong indent. No error is raised; the YAML comes out reshaped, and only the later strict validation might catch it.

src = next((leading_ws(line) for line in body if line.strip()), "")
notes = [src + line.lstrip() for line in comments]
merged = _insert_lines(lines, end, child, [*notes, *body], src)
...
moved = [indent + line[len(src) :] if line.strip() else line for line in extra]

Fix: Derive src from the first non-comment content line, and raise ValueError when a line's leading whitespace doesn't start with src instead of slicing it blindly.

🟡 **5. MEDIUM** — assert used as runtime check
esphome_device_builder/helpers/yaml/component.py:134-136

Risk: Under python -O the assert is removed. If _splice_into_domain_block ever returns None (for example, its header lookup disagrees with _find_top_level_block_bounds), merged becomes None. That fails later as an unrelated AttributeError, or None is returned as the YAML text, instead of a clear merge error.

spliced = _splice_into_domain_block(merged, key, "\n".join(block))
assert spliced is not None  # the block's bounds were found above
merged = spliced

Fix: Replace the assert with if spliced is None: raise ValueError(f"overlay {key}: could not splice into existing block") so the caller's except ValueError turns it into INTERNAL_ERROR.


Automated review by Kōan (Claude) HEAD=8dc9c3c 1 min 35s

@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.

@esphbot

Copy link
Copy Markdown
Contributor

Note

No code changes since the last review (8dc9c3c) — skipping. Push new commits or re-request a review to run again.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants