From e80933d6c73d1b3a0a31ce0b25caffdd2556932d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 28 Mar 2022 10:32:15 -0700 Subject: [PATCH] Force helpers to have a mandatory description (#68796) --- .../components/derivative/strings.json | 1 + .../components/switch_as_x/strings.json | 9 ++++---- script/hassfest/translations.py | 23 ++++++++++++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/derivative/strings.json b/homeassistant/components/derivative/strings.json index b225653cafa..b9ef15d652d 100644 --- a/homeassistant/components/derivative/strings.json +++ b/homeassistant/components/derivative/strings.json @@ -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", diff --git a/homeassistant/components/switch_as_x/strings.json b/homeassistant/components/switch_as_x/strings.json index cc50d1922cf..05863b0c5fe 100644 --- a/homeassistant/components/switch_as_x/strings.json +++ b/homeassistant/components/switch_as_x/strings.json @@ -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" } } } diff --git a/script/hassfest/translations.py b/script/hassfest/translations.py index 5e64c70210c..38392832261 100644 --- a/script/hassfest/translations.py +++ b/script/hassfest/translations.py @@ -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,