Surface automation required-groups and stop hiding their members as advanced#1908
Conversation
|
@esphbot review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1908 +/- ##
=======================================
Coverage 99.58% 99.58%
=======================================
Files 239 239
Lines 19361 19363 +2
=======================================
+ Hits 19280 19282 +2
Misses 81 81
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Reviewed. Clean bugfix. Reuses #924 constraint introspection for live registries. |
|
|
esphbot
left a comment
There was a problem hiding this comment.
No blocking issues found.
There was a problem hiding this comment.
Pull request overview
Updates the automations catalog generation so action/condition schemas can surface cross-field “must set one of …” constraints (from live ESPHome registries) and ensures required-choice fields aren’t hidden behind the “Advanced” section, fixing invalid YAML output in the structured automation editor.
Changes:
- Introspect ESPHome’s live automation action/condition registries to extract
cv.has_*_one_key(...)constraints and stamp them into generated automation bodies asrequired_groups. - Promote required-group member fields off
advancedand annotate their descriptions with “set at least/exactly one of …” hints. - Extend automation models/docs and add tests covering registry group extraction, catalog stamping, and served body payloads.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_sync_components_required_groups.py | Adds tests for extracting required-groups from vol.All chains and from (fake/live) ESPHome automation registries. |
| tests/test_automations_sync.py | Adds sync tests ensuring registry-provided required groups are emitted into automation bodies and that grouped fields are no longer advanced. |
| tests/test_automations_get_bodies.py | Ensures the shipped sensor.in_range body is served with required_groups and non-advanced group members. |
| script/sync_components.py | Implements live registry introspection, required-group extraction, and wiring into automations generation. |
| esphome_device_builder/models/automations.py | Adds required_groups to AutomationAction / AutomationCondition wire models. |
| esphome_device_builder/definitions/automations/conditions/sensor.in_range.json | Removes advanced from above/below, adds required_groups, and injects the “set at least one of” hint. |
| esphome_device_builder/definitions/automations/conditions/number.in_range.json | Same required-group + advanced demotion + hint treatment for number range conditions. |
| esphome_device_builder/definitions/automations/actions/ota.http_request.flash.json | Adds required_groups for md5 vs md5_url, promotes them off advanced, and injects the hint. |
| esphome_device_builder/definitions/automations/actions/homeassistant.service.json | Adds required_groups for service vs action and promotes the alias field off advanced. |
| esphome_device_builder/definitions/automations/actions/homeassistant.action.json | Same as above for the homeassistant.action entry. |
| esphome_device_builder/definitions/automations/actions/deep_sleep.enter.json | Adds a none_or_all required group for until + time_id and annotates/promotes accordingly. |
| docs/API.md | Documents required_groups on automations action/condition bodies and the “never advanced” constraint-member rule. |
| required_groups = _automation_required_groups(group_index, qualified, config_entries) | ||
| if required_groups: | ||
| config_entries = _promote_constraint_members(config_entries, required_groups) | ||
| entry = { |
There was a problem hiding this comment.
Fixed in 68acad1; the post-pass applier now clears required on every group member.
|
Addressed the suggestion in 68acad1: group members now drop per-field required at the generator level, since the group is the requirement and the bundle's Required on the preferred alias was the artifact. Also folded the stamping into a single post-pass applier and brought the branch up to date with main. @esphbot review |
|
@esphbot review |
PR Review — Surface automation required-groups and stop hiding their members as advancedClean, well-scoped bugfix — merge-ready. Verified against the branch HEAD; the prior review's one open suggestion is now resolved. Strengths:
Verification:
No blocking issues. Checklist
Automated review by Kōan (Claude) |
esphbot
left a comment
There was a problem hiding this comment.
No blocking issues found.
What does this implement/fix?
The automation editor writes
- sensor.in_range: {id: ...}with noaboveorbelow, and validation fails with "Must contain at least one of above, below." The generated condition definition marks both fieldsadvanced: true, so the structured editor never shows them; the schema bundle drops thecv.has_at_least_one_key(...)wrapper entirely, so the sync script had no way to see the constraint.The sync script now reads the live action/condition registries after the component import sweep and reuses the existing
cv.has_*_one_keyintrospection the component catalog got in #924: matching bodies gainrequired_groups, their members are promoted offadvanced, and the descriptions get the same "set at least one of" hint. Seven registry entries carry such groups; theifaction's groups name control flow keys (then,condition) that are stripped fromconfig_entries, so it is filtered out and six definitions change:sensor.in_range,number.in_range,deep_sleep.enter,homeassistant.service,homeassistant.action,ota.http_request.flash.AutomationAction/AutomationConditiongain arequired_groupsmodel field so the constraint reaches the wire; the slim index is unchanged.Notes for review: promoting all group members also surfaces the deprecated
servicealias onhomeassistant.service/homeassistant.action, matching how the component path treats constraint members. Triggers are out of scope;sensor.on_value_rangealready showsabove/belowand only lacks the hint, and triggers are not registry backed.Related issue or feature (if applicable):
Types of changes
bugfixnew-featureenhancementbreaking-changerefactordocsmaintenancecidependenciesFrontend coordination
Checklist
ruff,codespell, yaml/json/python checks).tests/where applicable.components.index.json/definitions/components/*.jsonhave not been hand-edited (regenerate viascript/sync_components.pyif a sync is needed).docs/ARCHITECTURE.mdand/ordocs/API.md.