From 74fa30e59d883faff09018e69352120146590c9c Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:05:18 +0200 Subject: [PATCH] Improve config flow type hints (g-m) (#124907) --- .../geonetnz_volcano/config_flow.py | 4 ++-- .../components/hlk_sw16/config_flow.py | 5 ++-- .../components/insteon/config_flow.py | 24 ++++++++++++++----- .../components/iotawatt/config_flow.py | 4 +++- .../components/kitchen_sink/config_flow.py | 4 +++- .../components/kmtronic/config_flow.py | 4 +++- homeassistant/components/kodi/config_flow.py | 20 +++++++++++----- .../components/lutron_caseta/config_flow.py | 8 +++++-- homeassistant/components/mill/config_flow.py | 8 +++++-- .../components/monoprice/config_flow.py | 4 +++- 10 files changed, 61 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/geonetnz_volcano/config_flow.py b/homeassistant/components/geonetnz_volcano/config_flow.py index 45a074d215c..cf3d5bc1139 100644 --- a/homeassistant/components/geonetnz_volcano/config_flow.py +++ b/homeassistant/components/geonetnz_volcano/config_flow.py @@ -12,7 +12,7 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, CONF_UNIT_SYSTEM, ) -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import config_validation as cv from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM @@ -26,7 +26,7 @@ from .const import ( @callback -def configured_instances(hass): +def configured_instances(hass: HomeAssistant) -> set[str]: """Return a set of configured GeoNet NZ Volcano instances.""" return { f"{entry.data[CONF_LATITUDE]}, {entry.data[CONF_LONGITUDE]}" diff --git a/homeassistant/components/hlk_sw16/config_flow.py b/homeassistant/components/hlk_sw16/config_flow.py index 8dd75561af3..34ee1ebd0e7 100644 --- a/homeassistant/components/hlk_sw16/config_flow.py +++ b/homeassistant/components/hlk_sw16/config_flow.py @@ -4,6 +4,7 @@ import asyncio from typing import Any from hlk_sw16 import create_hlk_sw16_connection +from hlk_sw16.protocol import SW16Client import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult @@ -27,7 +28,7 @@ DATA_SCHEMA = vol.Schema( ) -async def connect_client(hass, user_input): +async def connect_client(hass: HomeAssistant, user_input: dict[str, Any]) -> SW16Client: """Connect the HLK-SW16 client.""" client_aw = create_hlk_sw16_connection( host=user_input[CONF_HOST], @@ -41,7 +42,7 @@ async def connect_client(hass, user_input): return await client_aw -async def validate_input(hass: HomeAssistant, user_input): +async def validate_input(hass: HomeAssistant, user_input: dict[str, Any]) -> None: """Validate the user input allows us to connect.""" try: client = await connect_client(hass, user_input) diff --git a/homeassistant/components/insteon/config_flow.py b/homeassistant/components/insteon/config_flow.py index 7a701db1b82..6b048004ba1 100644 --- a/homeassistant/components/insteon/config_flow.py +++ b/homeassistant/components/insteon/config_flow.py @@ -64,7 +64,9 @@ class InsteonFlowHandler(ConfigFlow, domain=DOMAIN): modem_types = [STEP_PLM, STEP_HUB_V1, STEP_HUB_V2] return self.async_show_menu(step_id="user", menu_options=modem_types) - async def async_step_plm(self, user_input=None): + async def async_step_plm( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Set up the PLM modem type.""" errors = {} if user_input is not None: @@ -83,7 +85,9 @@ class InsteonFlowHandler(ConfigFlow, domain=DOMAIN): step_id=STEP_PLM, data_schema=data_schema, errors=errors ) - async def async_step_plm_manually(self, user_input=None): + async def async_step_plm_manually( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Set up the PLM modem type manually.""" errors = {} schema_defaults = {} @@ -97,15 +101,21 @@ class InsteonFlowHandler(ConfigFlow, domain=DOMAIN): step_id=STEP_PLM_MANUALLY, data_schema=data_schema, errors=errors ) - async def async_step_hubv1(self, user_input=None): + async def async_step_hubv1( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Set up the Hub v1 modem type.""" return await self._async_setup_hub(hub_version=1, user_input=user_input) - async def async_step_hubv2(self, user_input=None): + async def async_step_hubv2( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Set up the Hub v2 modem type.""" return await self._async_setup_hub(hub_version=2, user_input=user_input) - async def _async_setup_hub(self, hub_version, user_input): + async def _async_setup_hub( + self, hub_version: int, user_input: dict[str, Any] | None + ) -> ConfigFlowResult: """Set up the Hub versions 1 and 2.""" errors = {} if user_input is not None: @@ -144,7 +154,9 @@ class InsteonFlowHandler(ConfigFlow, domain=DOMAIN): await self.async_set_unique_id(DEFAULT_DISCOVERY_UNIQUE_ID) return await self.async_step_confirm_usb() - async def async_step_confirm_usb(self, user_input=None) -> ConfigFlowResult: + async def async_step_confirm_usb( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Confirm a USB discovery.""" if user_input is not None: return await self.async_step_plm({CONF_DEVICE: self._device_path}) diff --git a/homeassistant/components/iotawatt/config_flow.py b/homeassistant/components/iotawatt/config_flow.py index 187423c7d8b..668844a1c5c 100644 --- a/homeassistant/components/iotawatt/config_flow.py +++ b/homeassistant/components/iotawatt/config_flow.py @@ -75,7 +75,9 @@ class IOTaWattConfigFlow(ConfigFlow, domain=DOMAIN): return self.async_show_form(step_id="user", data_schema=schema, errors=errors) - async def async_step_auth(self, user_input=None): + async def async_step_auth( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Authenticate user if authentication is enabled on the IoTaWatt device.""" if user_input is None: user_input = {} diff --git a/homeassistant/components/kitchen_sink/config_flow.py b/homeassistant/components/kitchen_sink/config_flow.py index 9a0b78c80e6..8cff9321729 100644 --- a/homeassistant/components/kitchen_sink/config_flow.py +++ b/homeassistant/components/kitchen_sink/config_flow.py @@ -48,7 +48,9 @@ class KitchenSinkConfigFlow(ConfigFlow, domain=DOMAIN): """Reauth step.""" return await self.async_step_reauth_confirm() - async def async_step_reauth_confirm(self, user_input=None): + async def async_step_reauth_confirm( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Reauth confirm step.""" if user_input is None: return self.async_show_form(step_id="reauth_confirm") diff --git a/homeassistant/components/kmtronic/config_flow.py b/homeassistant/components/kmtronic/config_flow.py index f83d102ac05..6bf0b878f72 100644 --- a/homeassistant/components/kmtronic/config_flow.py +++ b/homeassistant/components/kmtronic/config_flow.py @@ -106,7 +106,9 @@ class KMTronicOptionsFlow(OptionsFlow): """Initialize options flow.""" self.config_entry = config_entry - async def async_step_init(self, user_input=None): + async def async_step_init( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Manage the options.""" if user_input is not None: return self.async_create_entry(title="", data=user_input) diff --git a/homeassistant/components/kodi/config_flow.py b/homeassistant/components/kodi/config_flow.py index 26b5214c733..ef0798220dd 100644 --- a/homeassistant/components/kodi/config_flow.py +++ b/homeassistant/components/kodi/config_flow.py @@ -140,7 +140,9 @@ class KodiConfigFlow(ConfigFlow, domain=DOMAIN): return await self.async_step_discovery_confirm() - async def async_step_discovery_confirm(self, user_input=None): + async def async_step_discovery_confirm( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Handle user-confirmation of discovered node.""" if user_input is None: return self.async_show_form( @@ -178,7 +180,9 @@ class KodiConfigFlow(ConfigFlow, domain=DOMAIN): return self._show_user_form(errors) - async def async_step_credentials(self, user_input=None): + async def async_step_credentials( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Handle username and password input.""" errors = {} @@ -203,7 +207,9 @@ class KodiConfigFlow(ConfigFlow, domain=DOMAIN): return self._show_credentials_form(errors) - async def async_step_ws_port(self, user_input=None): + async def async_step_ws_port( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Handle websocket port of discovered node.""" errors = {} @@ -249,7 +255,9 @@ class KodiConfigFlow(ConfigFlow, domain=DOMAIN): return self.async_abort(reason=reason) @callback - def _show_credentials_form(self, errors=None): + def _show_credentials_form( + self, errors: dict[str, str] | None = None + ) -> ConfigFlowResult: schema = vol.Schema( { vol.Optional( @@ -262,7 +270,7 @@ class KodiConfigFlow(ConfigFlow, domain=DOMAIN): ) return self.async_show_form( - step_id="credentials", data_schema=schema, errors=errors or {} + step_id="credentials", data_schema=schema, errors=errors ) @callback @@ -304,7 +312,7 @@ class KodiConfigFlow(ConfigFlow, domain=DOMAIN): ) @callback - def _get_data(self): + def _get_data(self) -> dict[str, Any]: return { CONF_NAME: self._name, CONF_HOST: self._host, diff --git a/homeassistant/components/lutron_caseta/config_flow.py b/homeassistant/components/lutron_caseta/config_flow.py index 703fbb813c6..cd566b767fb 100644 --- a/homeassistant/components/lutron_caseta/config_flow.py +++ b/homeassistant/components/lutron_caseta/config_flow.py @@ -95,7 +95,9 @@ class LutronCasetaFlowHandler(ConfigFlow, domain=DOMAIN): """Handle a flow initialized by homekit discovery.""" return await self.async_step_zeroconf(discovery_info) - async def async_step_link(self, user_input=None): + async def async_step_link( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Handle pairing with the hub.""" errors = {} # Abort if existing entry with matching host exists. @@ -198,7 +200,9 @@ class LutronCasetaFlowHandler(ConfigFlow, domain=DOMAIN): self._abort_if_unique_id_configured() return self.async_create_entry(title=ENTRY_DEFAULT_TITLE, data=self.data) - async def async_step_import_failed(self, user_input=None): + async def async_step_import_failed( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Make failed import surfaced to user.""" self.context["title_placeholders"] = {CONF_NAME: self.data[CONF_HOST]} diff --git a/homeassistant/components/mill/config_flow.py b/homeassistant/components/mill/config_flow.py index db1b2711575..7b2e5c3c4d5 100644 --- a/homeassistant/components/mill/config_flow.py +++ b/homeassistant/components/mill/config_flow.py @@ -43,7 +43,9 @@ class MillConfigFlow(ConfigFlow, domain=DOMAIN): return await self.async_step_local() return await self.async_step_cloud() - async def async_step_local(self, user_input=None): + async def async_step_local( + self, user_input: dict[str, str] | None = None + ) -> ConfigFlowResult: """Handle the local step.""" data_schema = vol.Schema({vol.Required(CONF_IP_ADDRESS): str}) if user_input is None: @@ -75,7 +77,9 @@ class MillConfigFlow(ConfigFlow, domain=DOMAIN): }, ) - async def async_step_cloud(self, user_input=None): + async def async_step_cloud( + self, user_input: dict[str, str] | None = None + ) -> ConfigFlowResult: """Handle the cloud step.""" data_schema = vol.Schema( {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str} diff --git a/homeassistant/components/monoprice/config_flow.py b/homeassistant/components/monoprice/config_flow.py index 5f0b1bf27b5..cac673e38c1 100644 --- a/homeassistant/components/monoprice/config_flow.py +++ b/homeassistant/components/monoprice/config_flow.py @@ -139,7 +139,9 @@ class MonopriceOptionsFlowHandler(OptionsFlow): return previous - async def async_step_init(self, user_input=None): + async def async_step_init( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: """Manage the options.""" if user_input is not None: return self.async_create_entry(