Skip to content

Add a --check mode to the devices.esphome.io importer - #3028

Merged
J. Nick Koston (bdraco) merged 6 commits into
mainfrom
sync-devices-check
Nov 6, 2026
Merged

J. Nick Koston (bdraco) merged 6 commits into
mainfrom
sync-devices-check

Conversation

@bdraco

Copy link
Copy Markdown
Member

What does this implement/fix?

Add a --check mode to the devices.esphome.io importer, so the devices repo's CI can ask the real importer whether a changed page would import, instead of keeping a hand-copied version of its rules.

python script/sync_esphome_devices.py --repo <devices checkout> --check --json \
  --device IoTiX-Adam --device M5Stack-NanoC6
# exits 1 and prints each skipped device's reason
  • --repo PATH reads an existing devices.esphome.io checkout instead of cloning; --device is repeatable and filters inside _iter_devices, so only the named folders are parsed.
  • --check implies --dry-run (the full-setup validation gate still runs), prints ok or skip <dir>: <reason> per device ({device, imported, reason} rows with --json), and exits 1 if any requested device would be skipped. A folder without a device page counts as a skip. Quoted file="..." fences now resolve too.
  • Used by Validate example configs with ESPHome and the Device Builder import rules devices.esphome.io#1938, which runs this inside a network-less container. Report helpers live in a new script/_sync_check.py, so sync_esphome_devices.py only gains the CLI wiring. Overlaps Accept every target platform as a devices.esphome.io SoC family #3026 in the same file (trivial merge).
Notes

Tests: tests/test_sync_esphome_devices_check.py. tests/test_sync_esphome_devices_psram.py::test_psram_allocating_components_scans_installed_esphome fails locally on unmodified main too; it depends on which esphome is installed.

Related issue or feature (if applicable):

  • fixes

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.

--repo uses an existing devices.esphome.io checkout, --device repeats, and
--check (dry run) prints each requested device's import result, as JSON with
--json, and exits 1 when any would be skipped. Quoted file= fence references
now resolve.
@bdraco

Copy link
Copy Markdown
Member Author

ESPHome Bot (@esphbot) review

@github-actions github-actions Bot added the enhancement Improvement to an existing feature label Nov 5, 2026
@bdraco
J. Nick Koston (bdraco) marked this pull request as ready for review November 5, 2026 23:11
Copilot AI balanced review requested due to automatic review settings November 5, 2026 23:11
@codspeed

codspeed Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 28 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing sync-devices-check (f0f1a8f) with main (fbf212d)

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

@esphbot

ESPHome Bot (esphbot) commented Nov 5, 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.

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3028   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files         300      300           
  Lines       26522    26522           
=======================================
  Hits        26461    26461           
  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.

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

Check mode bypasses the manifest ownership check, reporting slug collisions as successfully imported with exit code 0 even though a real sync skips them.

1 open issue
What changed in this PR

Adds an import-checking CLI so devices.esphome.io CI can reuse the Device Builder importer’s rules instead of duplicating them.

Changes:

  • Adds local-checkout support, repeatable device filters, and check-mode text or JSON reports with skip-based exit codes.
  • Supports quoted filenames in YAML fences.
  • Adds tests for reporting, filtering, missing devices, and invalid checkout paths.
File Description
tests/​test_sync_esphome_devices_check.py Tests the new CLI options and check reports.
script/​sync_esphome_devices.py Wires check mode, checkout selection, filtering, and quoted fence references.
script/​_sync_check.py Builds per-device results and formats text or JSON output.

Review effort: Balanced

Comment thread script/sync_esphome_devices.py Resolved
@bdraco

Copy link
Copy Markdown
Member Author

Fixed in fd91311:

  1. Slug collision: manifest_collides() runs even in dry-run and check mode (see the Copilot thread).
  2. The fallback reason now reads "no readable device page", and --check refuses --limit, so a device the limit cut off is never reported as missing.
  3. --json without --check, and --clean with --repo, now fail argument parsing.

ESPHome Bot (@esphbot) review

@esphbot

ESPHome Bot (esphbot) commented Nov 5, 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.

@bdraco
J. Nick Koston (bdraco) requested a balanced review from Copilot November 5, 2026 23:46
@bdraco

Copy link
Copy Markdown
Member Author

Fixed in 870a7d7: a real sync goes through _emit_manifest again, so a slug collision logs the same warning it used to. Only dry runs and --check call the side-effect-free manifest_collides. emit_manifest and manifest_collides now share one _collides helper, so the manifest is read once. Merged main (with #3026) in 27d9497.

ESPHome Bot (@esphbot) 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 block approval of the importer’s read-only check mode.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@esphbot

Copy link
Copy Markdown
Contributor

J. Nick Koston (@bdraco): Fixed in 870a7d7: a real sync goes through _emit_manifest again, so a slug collision logs the sa...

Verified. Real sync calls _emit_manifest (line 2559), so the warning is back. Dry run uses manifest_collides. Shared _collides reuses prior, so one read. Nothing outstanding.

@esphbot

Copy link
Copy Markdown
Contributor

PR Review — Add a --check mode to the devices.esphome.io importer

Merge-ready. The one remaining suggestion from the last review is fixed, and I found no new issues.

What the PR does well:

  • Real syncs call _emit_manifest directly again (script/sync_esphome_devices.py:2556-2560), so a slug collision logs its warning again. Only dry runs and --check use the side-effect-free manifest_collides.
  • emit_manifest and manifest_collides share one _collides(record, manifest_path, prior) helper (script/_board_import.py:410). emit_manifest passes in its existing prior parse, so the manifest is read only once. Ownership logic now lives in one place, so check mode and real syncs can't disagree.
  • emit_manifest returns None only when the slug collides, so treating _emit_manifest(...) is None as a collision is still correct.
  • The --device filter checks names against iterdir() results, so a crafted name can't reach paths outside the devices tree. _parse_args rejects flag combinations that would otherwise be ignored silently. Check mode never writes, prunes or clones, and tests assert this.

Needs attention:

  • Nothing blocking or advisory remains.

✅ Resolved since last review (1)

Previously-flagged issues verified fixed
  • script/sync_esphome_devices.py:2551 Real syncs no longer log a warning when a slug collides


Checklist

  • No hardcoded secrets
  • Input validation at boundaries (CLI args, --device, file= refs)
  • Check mode matches real import decisions
  • Collisions stay visible in real-sync logs
  • New behaviour covered by tests
  • No writes/prune/clone in check mode

Automated review by Kōan (Claude) HEAD=f0f1a8f 22s

@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 2ff818f into main Nov 6, 2026
24 of 26 checks passed
@bdraco
J. Nick Koston (bdraco) deleted the sync-devices-check branch November 6, 2026 00:07
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement Improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants