Force helpers to have a mandatory description (#68796)

This commit is contained in:
Paulus Schoutsen 2022-03-28 10:32:15 -07:00 committed by GitHub
parent 68a6359999
commit e80933d6c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 5 deletions

View File

@ -3,6 +3,7 @@
"step": { "step": {
"user": { "user": {
"title": "New Derivative sensor", "title": "New Derivative sensor",
"description": "Create a sensor that estimates the derivative of a sensor.",
"data": { "data": {
"name": "Name", "name": "Name",
"round": "Precision", "round": "Precision",

View File

@ -2,11 +2,12 @@
"title": "Switch as X", "title": "Switch as X",
"config": { "config": {
"step": { "step": {
"init": { "user": {
"title": "Make a switch a ...", "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": { "data": {
"entity_id": "Switch entity", "entity_id": "Switch",
"target_domain": "Type" "target_domain": "New Type"
} }
} }
} }

View File

@ -100,6 +100,7 @@ def gen_data_entry_schema(
integration: Integration, integration: Integration,
flow_title: int, flow_title: int,
require_step_title: bool, require_step_title: bool,
mandatory_description: str | None = None,
): ):
"""Generate a data entry schema.""" """Generate a data entry schema."""
step_title_class = vol.Required if require_step_title else vol.Optional step_title_class = vol.Required if require_step_title else vol.Optional
@ -138,7 +139,24 @@ def gen_data_entry_schema(
return value 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): def gen_strings_schema(config: Config, integration: Integration):
@ -151,6 +169,9 @@ def gen_strings_schema(config: Config, integration: Integration):
integration=integration, integration=integration,
flow_title=REMOVED, flow_title=REMOVED,
require_step_title=False, require_step_title=False,
mandatory_description=(
"user" if integration.integration_type == "helper" else None
),
), ),
vol.Optional("options"): gen_data_entry_schema( vol.Optional("options"): gen_data_entry_schema(
config=config, config=config,