From 627d6f7803728cbd188f7a7060d8b2c747a18555 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 31 May 2022 10:33:34 +0200 Subject: [PATCH] Ensure description_placeholders is always typed (#72716) --- homeassistant/auth/providers/__init__.py | 2 +- .../components/homewizard/config_flow.py | 8 +++--- .../components/tankerkoenig/config_flow.py | 2 +- homeassistant/config_entries.py | 7 ++++-- homeassistant/data_entry_flow.py | 25 ++++++++++++------- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/homeassistant/auth/providers/__init__.py b/homeassistant/auth/providers/__init__.py index 63389059051..6feb4b26759 100644 --- a/homeassistant/auth/providers/__init__.py +++ b/homeassistant/auth/providers/__init__.py @@ -272,7 +272,7 @@ class LoginFlow(data_entry_flow.FlowHandler): if not errors: return await self.async_finish(self.credential) - description_placeholders: dict[str, str | None] = { + description_placeholders: dict[str, str] = { "mfa_module_name": auth_module.name, "mfa_module_id": auth_module.id, } diff --git a/homeassistant/components/homewizard/config_flow.py b/homeassistant/components/homewizard/config_flow.py index df883baf3b1..7d06f08ce74 100644 --- a/homeassistant/components/homewizard/config_flow.py +++ b/homeassistant/components/homewizard/config_flow.py @@ -2,7 +2,7 @@ from __future__ import annotations import logging -from typing import Any +from typing import Any, cast from homewizard_energy import HomeWizardEnergy from homewizard_energy.errors import DisabledError, UnsupportedError @@ -160,9 +160,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return self.async_show_form( step_id="discovery_confirm", description_placeholders={ - CONF_PRODUCT_TYPE: self.config[CONF_PRODUCT_TYPE], - CONF_SERIAL: self.config[CONF_SERIAL], - CONF_IP_ADDRESS: self.config[CONF_IP_ADDRESS], + CONF_PRODUCT_TYPE: cast(str, self.config[CONF_PRODUCT_TYPE]), + CONF_SERIAL: cast(str, self.config[CONF_SERIAL]), + CONF_IP_ADDRESS: cast(str, self.config[CONF_IP_ADDRESS]), }, ) diff --git a/homeassistant/components/tankerkoenig/config_flow.py b/homeassistant/components/tankerkoenig/config_flow.py index 345b034b027..dd5893fe35f 100644 --- a/homeassistant/components/tankerkoenig/config_flow.py +++ b/homeassistant/components/tankerkoenig/config_flow.py @@ -133,7 +133,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN): if not user_input: return self.async_show_form( step_id="select_station", - description_placeholders={"stations_count": len(self._stations)}, + description_placeholders={"stations_count": str(len(self._stations))}, data_schema=vol.Schema( {vol.Required(CONF_STATIONS): cv.multi_select(self._stations)} ), diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 49b2059b2a2..df633009138 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -1403,7 +1403,10 @@ class ConfigFlow(data_entry_flow.FlowHandler): @callback def async_abort( - self, *, reason: str, description_placeholders: dict | None = None + self, + *, + reason: str, + description_placeholders: Mapping[str, str] | None = None, ) -> data_entry_flow.FlowResult: """Abort the config flow.""" # Remove reauth notification if no reauth flows are in progress @@ -1477,7 +1480,7 @@ class ConfigFlow(data_entry_flow.FlowHandler): title: str, data: Mapping[str, Any], description: str | None = None, - description_placeholders: dict | None = None, + description_placeholders: Mapping[str, str] | None = None, options: Mapping[str, Any] | None = None, ) -> data_entry_flow.FlowResult: """Finish config flow and create a config entry.""" diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 628a89dd89b..714cea07044 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -52,7 +52,7 @@ class AbortFlow(FlowError): """Exception to indicate a flow needs to be aborted.""" def __init__( - self, reason: str, description_placeholders: dict | None = None + self, reason: str, description_placeholders: Mapping[str, str] | None = None ) -> None: """Initialize an abort flow exception.""" super().__init__(f"Flow aborted: {reason}") @@ -75,7 +75,7 @@ class FlowResult(TypedDict, total=False): required: bool errors: dict[str, str] | None description: str | None - description_placeholders: dict[str, Any] | None + description_placeholders: Mapping[str, str | None] | None progress_action: str url: str reason: str @@ -422,7 +422,7 @@ class FlowHandler: step_id: str, data_schema: vol.Schema | None = None, errors: dict[str, str] | None = None, - description_placeholders: dict[str, Any] | None = None, + description_placeholders: Mapping[str, str | None] | None = None, last_step: bool | None = None, ) -> FlowResult: """Return the definition of a form to gather user input.""" @@ -444,7 +444,7 @@ class FlowHandler: title: str, data: Mapping[str, Any], description: str | None = None, - description_placeholders: dict | None = None, + description_placeholders: Mapping[str, str] | None = None, ) -> FlowResult: """Finish config flow and create a config entry.""" return { @@ -460,7 +460,10 @@ class FlowHandler: @callback def async_abort( - self, *, reason: str, description_placeholders: dict | None = None + self, + *, + reason: str, + description_placeholders: Mapping[str, str] | None = None, ) -> FlowResult: """Abort the config flow.""" return _create_abort_data( @@ -469,7 +472,11 @@ class FlowHandler: @callback def async_external_step( - self, *, step_id: str, url: str, description_placeholders: dict | None = None + self, + *, + step_id: str, + url: str, + description_placeholders: Mapping[str, str] | None = None, ) -> FlowResult: """Return the definition of an external step for the user to take.""" return { @@ -497,7 +504,7 @@ class FlowHandler: *, step_id: str, progress_action: str, - description_placeholders: dict | None = None, + description_placeholders: Mapping[str, str] | None = None, ) -> FlowResult: """Show a progress message to the user, without user input allowed.""" return { @@ -525,7 +532,7 @@ class FlowHandler: *, step_id: str, menu_options: list[str] | dict[str, str], - description_placeholders: dict | None = None, + description_placeholders: Mapping[str, str] | None = None, ) -> FlowResult: """Show a navigation menu to the user. @@ -547,7 +554,7 @@ def _create_abort_data( flow_id: str, handler: str, reason: str, - description_placeholders: dict | None = None, + description_placeholders: Mapping[str, str] | None = None, ) -> FlowResult: """Return the definition of an external step for the user to take.""" return {