Skip to content

Derive ethernet type platforms from the schema gates - #3095

Merged
J. Nick Koston (bdraco) merged 3 commits into
mainfrom
ethernet-type-platforms-from-schema
Nov 23, 2026
Merged

J. Nick Koston (bdraco) merged 3 commits into
mainfrom
ethernet-type-platforms-from-schema

Conversation

@bdraco

Copy link
Copy Markdown
Member

What does this implement/fix?

Ethernet's per-platform type choices now come from each type's cv.only_on gate in the schema, so the new RP2-only USB type (esphome/esphome#23138) is offered on RP2 instead of on ESP32.

# Before: everything outside the RP2-only chips lands on esp32, USB included
rp2 = set(_ethernet.RP2_ETHERNET_TYPES)
esp32 = set(_ethernet.ETHERNET_TYPES) - (rp2 - set(_ethernet.SPI_ETHERNET_TYPES))

# After: read each typed_schema branch's platform gate
gates = {t: _platform_set(branch) for t, branch in _typed_branch_schemas(_ethernet.CONFIG_SCHEMA).items()}
esp32 = {t for t, gate in gates.items() if gate is None or "esp32" in gate}
rp2 = set(_ethernet.RP2_ETHERNET_TYPES) | (gates.keys() - esp32)
Details

The ESP32 SPI chips (DM9051, CH390, KSZ8851SNL) share an SPI schema gated to ESP32 and RP2; esphome's _validate keeps them off RP2, so RP2_ETHERNET_TYPES stays the base of the RP2 list.

The live-schema test no longer pins the old constant arithmetic: it checks the RP2-only chips and USB land only on RP2, DM9051 stays off RP2, and every type lands on some platform. It passes against esphome dev and against the esphome/esphome#23138 head. The shipped catalog JSON is not regenerated here.

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.

@bdraco

Copy link
Copy Markdown
Member Author

Bluetooth Devices Bot (@bluetoothbot) review

@codspeed

codspeed Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 28 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing ethernet-type-platforms-from-schema (2283068) with main (c0d0110)

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.

🟡 Changes recommended

The gate-widening logic would drop USB from RP2 when its gate includes both platforms, so RP2-gated non-SPI types must be included independently of ESP32 membership.

1 open issue
What changed in this PR

This PR updates the catalog generator to derive Ethernet type availability from schema platform gates, placing the new RP2-only USB type on RP2 rather than ESP32.

Changes:

  • Read per-type platform gates while preserving existing RP2 SPI restrictions.
  • Update live-schema tests to check platform assignments and complete type coverage.
  • Leave generated catalog JSON unchanged.
File Description
tests/​test_sync_components_ethernet_types.py Updates assertions for schema-derived Ethernet availability.
script/​sync_components.py Uses schema gates to calculate Ethernet type options by platform.

Review effort: Balanced (adaptive)

Comment thread script/sync_components.py Resolved
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3095   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files         300      300           
  Lines       26564    26564           
=======================================
  Hits        26503    26503           
  Misses         61       61           
Flag Coverage Δ
py3.12 99.73% <ø> (ø)
py3.14 99.62% <ø> (ø)

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

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

@bluetoothbot

Bluetooth Devices Bot (bluetoothbot) commented Nov 23, 2026 •

Copy link
Copy Markdown

Previous review — superseded by a newer review below.

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Member Author

Bluetooth Devices Bot (@bluetoothbot) review

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 remain for the Ethernet platform-choice update.

No open issues 🎉

1 resolved since last review

Review effort: Balanced (adaptive)

@bluetoothbot

Copy link
Copy Markdown

PR Review — Derive ethernet type platforms from the schema gates

Mergeable. The forward-compat gap from the last review is fixed, and only a small defensive nit remains.

The RP2 list now comes from each type's RP2 gate (RP2_CANONICAL_PLATFORM in gate). It no longer uses "not on ESP32" as a stand-in. A widened USB gate of {esp32, rp2} keeps USB on both platforms, and a type gated only to some third platform no longer lands on RP2. The new test_widened_gate_keeps_type_on_rp2 covers this with monkeypatched gates, so the test doesn't depend on an esphome bump. It also checks that the SPI chip (DM9051) stays off RP2 even when its gate includes RP2. The live-schema test checks placement rather than repeating the constant arithmetic.


✅ Resolved since last review (1)

Previously-flagged issues verified fixed
  • script/sync_components.py:8439 RP2 list is built as 'not ESP32' rather than read from the RP2 gate


Checklist

  • Logic matches stated forward-compat behaviour
  • Tests verify observable behaviour
  • No hardcoded secrets / security issues

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

Copy link
Copy Markdown

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) marked this pull request as ready for review November 23, 2026 22:14
@bdraco
J. Nick Koston (bdraco) merged commit c8a54a0 into main Nov 23, 2026
31 checks passed
@bdraco
J. Nick Koston (bdraco) deleted the ethernet-type-platforms-from-schema branch November 23, 2026 22:15

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 Ethernet catalog generator changes.

No open issues 🎉

Review effort: Balanced (adaptive)

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 25, 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.

3 participants