Skip to content

[config] Add --no-defaults flag to config command#16718

Open
jesserockz wants to merge 1 commit into
devfrom
jesserockz-2026-273
Open

[config] Add --no-defaults flag to config command#16718
jesserockz wants to merge 1 commit into
devfrom
jesserockz-2026-273

Conversation

@jesserockz
Copy link
Copy Markdown
Member

@jesserockz jesserockz commented May 29, 2026

What does this implement/fix?

Adds a --no-defaults flag to esphome config that emits only the user-supplied configuration, without the values voluptuous fills in from schema defaults.

Today the config command dumps the fully-validated config, which buries the few keys the user actually wrote under hundreds of injected defaults (every framework knob, every wifi/api timeout, etc.). The new flag is useful for diffing against another machine's config, sharing a minimal reproduction in an issue, or just sanity-checking what you actually typed after substitutions and packages are resolved.

Mechanically: validate_config now deep-copies the config dict into result.user_config right after substitutions/packages/extend-remove are resolved but before preload_core_config (the first step that injects defaults). Substitutions are re-added at the top of the snapshot so the output is a faithful "user YAML" view. When --no-defaults is set, command_config dumps that snapshot instead of the validated config.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — policy
  • Developer breaking change (an API change that could break external components) — policy
  • Undocumented C++ API change (removal or change of undocumented public methods that lambda users may depend on) — policy
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

  • fixes

Pull request in esphome.io with documentation (if applicable):

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040/RP2350
  • BK72xx
  • RTL87xx
  • LN882x
  • nRF52840

Example entry for config.yaml:

# Example config.yaml

Usage:

```
esphome config my-device.yaml --no-defaults
```

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under `tests/` folder).

If user exposed functionality or configuration variables are added/changed:

Lets users see only the configuration they wrote, without the schema
defaults that validation injects, by dumping a pre-validation snapshot
captured on the Config object.
Copilot AI review requested due to automatic review settings May 29, 2026 04:55
@jesserockz jesserockz requested a review from a team as a code owner May 29, 2026 04:55
@esphome
Copy link
Copy Markdown
Contributor

esphome Bot commented May 29, 2026

👋 Hi there! This PR modifies 2 file(s) with codeowners.

@esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏

Note: Automatic review request may have failed, but you're still welcome to review.

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

Adds an esphome config --no-defaults flag that emits only the user-supplied configuration, omitting the many schema defaults that voluptuous would otherwise inject. validate_config() now deep-copies the config into result.user_config after substitutions/packages/extend-remove are resolved but before preload_core_config() and full schema validation, and command_config() dumps that snapshot when the new flag is set.

Changes:

  • Add a user_config snapshot field on Config populated in validate_config() with substitutions re-added at the front.
  • Add --no-defaults CLI flag and corresponding branch in command_config() with a warning-and-fallback path when the snapshot is unavailable.
  • Add unit tests for snapshot capture/independence and for the new command_config branch (including the warning fallback and skipping strip_default_ids).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
esphome/config.py Imports copy, declares Config.user_config, and snapshots the resolved user config before defaults are injected.
esphome/main.py Adds the --no-defaults argparse option and a branch in command_config() that dumps config.user_config (or warns and falls back).
tests/unit_tests/test_substitutions.py Adds tests verifying the snapshot's contents, substitutions ordering, and that it is an independent deep copy.
tests/unit_tests/test_main.py Adds tests for --no-defaults dumping the snapshot, warning-and-fallback when missing, and skipping strip_default_ids.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 29, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 75.90%. Comparing base (4b8e06b) to head (63f2143).
⚠️ Report is 4 commits behind head on dev.

Files with missing lines Patch % Lines
esphome/__main__.py 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #16718      +/-   ##
==========================================
+ Coverage   75.88%   75.90%   +0.01%     
==========================================
  Files          69       69              
  Lines       14599    14611      +12     
  Branches     2107     2110       +3     
==========================================
+ Hits        11078    11090      +12     
  Misses       3067     3067              
  Partials      454      454              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@swoboda1337
Copy link
Copy Markdown
Member

@esphbot review

@esphbot
Copy link
Copy Markdown

esphbot commented Jun 3, 2026

Code Review

⚠️ The automated review could not be formatted into the standard structure. Re-run /review to retry.


Automated review by Kōan63f2143

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants