Improve config flow type hints (g-m) (#124907)

This commit is contained in:
epenet 2024-08-30 11:05:18 +02:00 committed by GitHub
parent 6833af6286
commit 74fa30e59d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 61 additions and 24 deletions

View file

@ -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]}"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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