mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Force helpers to have a mandatory description (#68796)
This commit is contained in:
parent
68a6359999
commit
e80933d6c7
@ -3,6 +3,7 @@
|
||||
"step": {
|
||||
"user": {
|
||||
"title": "New Derivative sensor",
|
||||
"description": "Create a sensor that estimates the derivative of a sensor.",
|
||||
"data": {
|
||||
"name": "Name",
|
||||
"round": "Precision",
|
||||
|
@ -2,11 +2,12 @@
|
||||
"title": "Switch as X",
|
||||
"config": {
|
||||
"step": {
|
||||
"init": {
|
||||
"title": "Make a switch a ...",
|
||||
"user": {
|
||||
"title": "Change switch device type",
|
||||
"description": "Pick a switch that you want to show up in Home Assistant as a light, cover or anything else. The original switch will be hidden.",
|
||||
"data": {
|
||||
"entity_id": "Switch entity",
|
||||
"target_domain": "Type"
|
||||
"entity_id": "Switch",
|
||||
"target_domain": "New Type"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,7 @@ def gen_data_entry_schema(
|
||||
integration: Integration,
|
||||
flow_title: int,
|
||||
require_step_title: bool,
|
||||
mandatory_description: str | None = None,
|
||||
):
|
||||
"""Generate a data entry schema."""
|
||||
step_title_class = vol.Required if require_step_title else vol.Optional
|
||||
@ -138,7 +139,24 @@ def gen_data_entry_schema(
|
||||
|
||||
return value
|
||||
|
||||
return vol.All(vol.Schema(schema), data_description_validator)
|
||||
validators = [vol.Schema(schema), data_description_validator]
|
||||
|
||||
if mandatory_description is not None:
|
||||
|
||||
def validate_description_set(value):
|
||||
"""Validate description is set."""
|
||||
steps = value["step"]
|
||||
if mandatory_description not in steps:
|
||||
raise vol.Invalid(f"{mandatory_description} needs to be defined")
|
||||
|
||||
if "description" not in steps[mandatory_description]:
|
||||
raise vol.Invalid(f"Step {mandatory_description} needs a description")
|
||||
|
||||
return value
|
||||
|
||||
validators.append(validate_description_set)
|
||||
|
||||
return vol.All(*validators)
|
||||
|
||||
|
||||
def gen_strings_schema(config: Config, integration: Integration):
|
||||
@ -151,6 +169,9 @@ def gen_strings_schema(config: Config, integration: Integration):
|
||||
integration=integration,
|
||||
flow_title=REMOVED,
|
||||
require_step_title=False,
|
||||
mandatory_description=(
|
||||
"user" if integration.integration_type == "helper" else None
|
||||
),
|
||||
),
|
||||
vol.Optional("options"): gen_data_entry_schema(
|
||||
config=config,
|
||||
|
Loading…
x
Reference in New Issue
Block a user