Ensure description_placeholders is always typed (#72716)

This commit is contained in:
epenet 2022-05-31 10:33:34 +02:00 committed by GitHub
parent db9c586404
commit 627d6f7803
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 17 deletions

View file

@ -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,
}

View file

@ -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]),
},
)

View file

@ -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)}
),

View file

@ -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."""

View file

@ -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 {