[config] Add --no-defaults flag to config command#16718
Conversation
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.
|
👋 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. |
There was a problem hiding this comment.
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_configsnapshot field onConfigpopulated invalidate_config()with substitutions re-added at the front. - Add
--no-defaultsCLI flag and corresponding branch incommand_config()with a warning-and-fallback path when the snapshot is unavailable. - Add unit tests for snapshot capture/independence and for the new
command_configbranch (including the warning fallback and skippingstrip_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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
|
@esphbot review |
Code Review
Automated review by Kōan63f2143 |
What does this implement/fix?
Adds a
--no-defaultsflag toesphome configthat emits only the user-supplied configuration, without the values voluptuous fills in from schema defaults.Today the
configcommand 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_confignow deep-copies the config dict intoresult.user_configright after substitutions/packages/extend-remove are resolved but beforepreload_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-defaultsis set,command_configdumps that snapshot instead of the validated config.Types of changes
Related issue or feature (if applicable):
Pull request in esphome.io with documentation (if applicable):
Test Environment
Example entry for
config.yaml:# Example config.yamlUsage:
```
esphome config my-device.yaml --no-defaults
```
Checklist:
If user exposed functionality or configuration variables are added/changed: