New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support shorthand templates in condition actions #61177
Conversation
|
||
def dynamic_template_condition_action(config: dict) -> dict: | ||
"""Validate and convert a shorthand template condition to a template condition.""" | ||
schema = vol.Schema( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define this outside of this function.
@@ -1207,6 +1207,40 @@ def STATE_CONDITION_SCHEMA(value: Any) -> dict: # pylint: disable=invalid-name | |||
) | |||
) | |||
|
|||
|
|||
def dynamic_template_condition_action(config: dict) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative:
dynamic_template_condition_action = vol.All(
vol.Schema(…),
lambda config: {
**config,
CONF_VALUE_TEMPLATE: config[CONF_CONDITION],
CONF_CONDITION: "template"
}
)
"zone": ZONE_CONDITION_SCHEMA, | ||
}, | ||
), | ||
dynamic_template_condition_action, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the broken test this breaks the validation message.
if default_schema: | ||
with contextlib.suppress(vol.Invalid): | ||
return cast(Dict[Hashable, Any], default_schema(value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will hide error messages from the default validator, not sure if that's acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
Proposed change
Support shorthand templates in condition actions
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: