Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve config flow type hints (part 1) #124343

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions homeassistant/components/airtouch4/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Config flow for AirTouch4."""

from typing import Any

from airtouch4pyapi import AirTouch, AirTouchStatus
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST

from .const import DOMAIN
Expand All @@ -16,7 +18,9 @@ class AirtouchConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle a flow initialized by the user."""
if user_input is None:
return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA)
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/ambient_station/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

from typing import Any

from aioambient import API
from aioambient.errors import AmbientError
import voluptuous as vol
Expand Down Expand Up @@ -32,7 +34,9 @@ async def _show_form(self, errors: dict | None = None) -> ConfigFlowResult:
errors=errors if errors else {},
)

async def async_step_user(self, user_input: dict | None = None) -> ConfigFlowResult:
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the start of the config flow."""
if not user_input:
return await self._show_form()
Expand Down
12 changes: 10 additions & 2 deletions homeassistant/components/control4/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
from __future__ import annotations

import logging
from typing import Any

from aiohttp.client_exceptions import ClientError
from pyControl4.account import C4Account
from pyControl4.director import C4Director
from pyControl4.error_handling import NotFound, Unauthorized
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
OptionsFlow,
)
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
Expand Down Expand Up @@ -93,7 +99,9 @@ class Control4ConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the initial step."""
errors = {}
if user_input is not None:
Expand Down
13 changes: 11 additions & 2 deletions homeassistant/components/dexcom/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

from __future__ import annotations

from typing import Any

from pydexcom import AccountError, Dexcom, SessionError
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
OptionsFlow,
)
from homeassistant.const import CONF_PASSWORD, CONF_UNIT_OF_MEASUREMENT, CONF_USERNAME
from homeassistant.core import callback

Expand All @@ -25,7 +32,9 @@ class DexcomConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the initial step."""
errors = {}
if user_input is not None:
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/econet/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Config flow to configure the EcoNet component."""

from typing import Any

from pyeconet import EcoNetApiInterface
from pyeconet.errors import InvalidCredentialsError, PyeconetError
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD

from .const import DOMAIN
Expand All @@ -24,7 +26,9 @@ def __init__(self) -> None:
}
)

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the start of the config flow."""
if not user_input:
return self.async_show_form(
Expand Down
10 changes: 7 additions & 3 deletions homeassistant/components/emulated_roku/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Config flow to configure emulated_roku component."""

from typing import Any

import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_NAME
from homeassistant.core import callback

Expand All @@ -22,9 +24,11 @@ class EmulatedRokuFlowHandler(ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle a flow initialized by the user."""
errors = {}
errors: dict[str, str] = {}

if user_input is not None:
self._async_abort_entries_match({CONF_NAME: user_input[CONF_NAME]})
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/enocean/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Config flows for the ENOcean integration."""

from typing import Any

import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_DEVICE

from . import dongle
Expand Down Expand Up @@ -32,7 +34,9 @@ async def async_step_import(self, data=None):

return self.create_enocean_entry(data)

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle an EnOcean config flow start."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/environment_canada/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Config flow for Environment Canada integration."""

import logging
from typing import Any
import xml.etree.ElementTree as ET

import aiohttp
from env_canada import ECWeather, ec_exc
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_LANGUAGE, CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.helpers import config_validation as cv

Expand Down Expand Up @@ -46,7 +47,9 @@ class EnvironmentCanadaConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the initial step."""
errors = {}
if user_input is not None:
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/epson/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Config flow for epson integration."""

import logging
from typing import Any

import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT

from . import validate_projector
Expand All @@ -26,7 +27,9 @@ class EpsonConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the initial step."""
errors = {}
if user_input is not None:
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/flick_electric/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import asyncio
import logging
from typing import Any

from pyflick.authentication import AuthException, SimpleFlickAuth
from pyflick.const import DEFAULT_CLIENT_ID, DEFAULT_CLIENT_SECRET
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
Expand Down Expand Up @@ -55,7 +56,9 @@ async def _validate_input(self, user_input):

return token is not None

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle gathering login info."""
errors = {}
if user_input is not None:
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/flo/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Config flow for flo integration."""

from typing import Any

from aioflo import async_get_api
from aioflo.errors import RequestError
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
Expand Down Expand Up @@ -36,7 +38,9 @@ class FloConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the initial step."""
errors = {}
if user_input is not None:
Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/forked_daapd/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from contextlib import suppress
import logging
from typing import Any

from pyforked_daapd import ForkedDaapdAPI
import voluptuous as vol
Expand Down Expand Up @@ -135,7 +136,9 @@ async def validate_input(self, user_input):
)
return validate_result

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle a forked-daapd config flow start.

Manage device specific parameters.
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/foscam/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Config flow for foscam integration."""

from typing import Any

from libpyfoscam import FoscamCamera
from libpyfoscam.foscam import (
ERROR_FOSCAM_AUTH,
Expand All @@ -8,7 +10,7 @@
)
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
Expand Down Expand Up @@ -90,7 +92,9 @@ async def _validate_and_create(self, data):

return self.async_create_entry(title=name, data=data)

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the initial step."""
errors = {}

Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/freedompro/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Config flow to configure Freedompro."""

from typing import Any

from pyfreedompro import get_list
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
Expand Down Expand Up @@ -45,7 +47,9 @@ class FreedomProConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Show the setup form to the user."""
if user_input is None:
return self.async_show_form(
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/geonetnz_quakes/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Config flow to configure the GeoNet NZ Quakes integration."""

import logging
from typing import Any

import voluptuous as vol

from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import (
CONF_LATITUDE,
CONF_LONGITUDE,
Expand Down Expand Up @@ -48,7 +49,9 @@ async def async_step_import(self, import_config):
"""Import a config entry from configuration.yaml."""
return await self.async_step_user(import_config)

async def async_step_user(self, user_input=None):
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the start of the config flow."""
_LOGGER.debug("User input: %s", user_input)
if not user_input:
Expand Down
Loading
Loading