Skip to content

Commit

Permalink
Improve config flow type hints (g-m) (#124907)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Aug 30, 2024
1 parent 6833af6 commit 74fa30e
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 24 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/geonetnz_volcano/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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

Expand All @@ -26,7 +26,7 @@


@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]}"
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/hlk_sw16/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand All @@ -27,7 +28,7 @@
)


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],
Expand All @@ -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)
Expand Down
24 changes: 18 additions & 6 deletions homeassistant/components/insteon/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ async def async_step_user(
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:
Expand All @@ -83,7 +85,9 @@ async def async_step_plm(self, user_input=None):
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 = {}
Expand All @@ -97,15 +101,21 @@ async def async_step_plm_manually(self, user_input=None):
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:
Expand Down Expand Up @@ -144,7 +154,9 @@ async def async_step_usb(
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})
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/iotawatt/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ async def async_step_user(

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 = {}
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/kitchen_sink/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ async def async_step_reauth(
"""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")
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/kmtronic/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def __init__(self, config_entry: ConfigEntry) -> None:
"""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)
Expand Down
20 changes: 14 additions & 6 deletions homeassistant/components/kodi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ async def async_step_zeroconf(

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(
Expand Down Expand Up @@ -178,7 +180,9 @@ async def async_step_user(

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 = {}

Expand All @@ -203,7 +207,9 @@ async def async_step_credentials(self, user_input=None):

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 = {}

Expand Down Expand Up @@ -249,7 +255,9 @@ async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResu
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(
Expand All @@ -262,7 +270,7 @@ def _show_credentials_form(self, errors=None):
)

return self.async_show_form(
step_id="credentials", data_schema=schema, errors=errors or {}
step_id="credentials", data_schema=schema, errors=errors
)

@callback
Expand Down Expand Up @@ -304,7 +312,7 @@ def _create_entry(self):
)

@callback
def _get_data(self):
def _get_data(self) -> dict[str, Any]:
return {
CONF_NAME: self._name,
CONF_HOST: self._host,
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/lutron_caseta/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ async def async_step_homekit(
"""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.
Expand Down Expand Up @@ -198,7 +200,9 @@ async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResu
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]}

Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/mill/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ async def async_step_user(
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:
Expand Down Expand Up @@ -75,7 +77,9 @@ async def async_step_local(self, user_input=None):
},
)

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}
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/monoprice/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def _previous_sources(self):

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(
Expand Down

0 comments on commit 74fa30e

Please sign in to comment.