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

Avoid import dhcp, ssdp, zeroconf in config_flow.py when only used for type checking #135373

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions homeassistant/components/airgradient/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Config flow for Airgradient."""

from typing import Any
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from airgradient import (
AirGradientClient,
Expand All @@ -11,13 +13,15 @@
from awesomeversion import AwesomeVersion
import voluptuous as vol

from homeassistant.components import zeroconf
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_MODEL
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import DOMAIN

if TYPE_CHECKING:
from homeassistant.components.zeroconf import ZeroconfServiceInfo

MIN_VERSION = AwesomeVersion("3.1.1")


Expand All @@ -37,7 +41,7 @@ async def set_configuration_source(self) -> None:
await self.client.set_configuration_control(ConfigurationControl.LOCAL)

async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
self, discovery_info: ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Handle zeroconf discovery."""
self.data[CONF_HOST] = host = discovery_info.host
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/airzone/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from __future__ import annotations

import logging
from typing import Any
from typing import TYPE_CHECKING, Any

from aioairzone.const import DEFAULT_PORT, DEFAULT_SYSTEM_ID
from aioairzone.exceptions import AirzoneError, InvalidSystem
from aioairzone.localapi import AirzoneLocalApi, ConnectionOptions
import voluptuous as vol

from homeassistant.components import dhcp
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_ID, CONF_PORT
from homeassistant.data_entry_flow import AbortFlow
Expand All @@ -19,6 +18,9 @@

from .const import DOMAIN

if TYPE_CHECKING:
from homeassistant.components.dhcp import DhcpServiceInfo

_LOGGER = logging.getLogger(__name__)

CONFIG_SCHEMA = vol.Schema(
Expand Down Expand Up @@ -93,7 +95,7 @@ async def async_step_user(
)

async def async_step_dhcp(
self, discovery_info: dhcp.DhcpServiceInfo
self, discovery_info: DhcpServiceInfo
) -> ConfigFlowResult:
"""Handle DHCP discovery."""
self._discovered_ip = discovery_info.ip
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/androidtv_remote/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from collections.abc import Mapping
import logging
from typing import Any
from typing import TYPE_CHECKING, Any

from androidtvremote2 import (
AndroidTVRemote,
Expand All @@ -14,7 +14,6 @@
)
import voluptuous as vol

from homeassistant.components import zeroconf
from homeassistant.config_entries import (
SOURCE_REAUTH,
ConfigEntry,
Expand All @@ -35,6 +34,9 @@
from .const import CONF_APP_ICON, CONF_APP_NAME, CONF_APPS, CONF_ENABLE_IME, DOMAIN
from .helpers import create_api, get_enable_ime

if TYPE_CHECKING:
from homeassistant.components.zeroconf import ZeroconfServiceInfo

_LOGGER = logging.getLogger(__name__)

APPS_NEW_ID = "NewApp"
Expand Down Expand Up @@ -142,7 +144,7 @@ async def async_step_pair(
)

async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
self, discovery_info: ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Handle zeroconf discovery."""
_LOGGER.debug("Android TV device found via zeroconf: %s", discovery_info)
Expand Down
9 changes: 6 additions & 3 deletions homeassistant/components/awair/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
from __future__ import annotations

from collections.abc import Mapping
from typing import Any, Self, cast
from typing import TYPE_CHECKING, Any, Self, cast

from aiohttp.client_exceptions import ClientError
from python_awair import Awair, AwairLocal, AwairLocalDevice
from python_awair.exceptions import AuthError, AwairError
from python_awair.user import AwairUser
import voluptuous as vol

from homeassistant.components import onboarding, zeroconf
from homeassistant.components import onboarding
from homeassistant.config_entries import SOURCE_ZEROCONF, ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_DEVICE, CONF_HOST
from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import DOMAIN, LOGGER

if TYPE_CHECKING:
from homeassistant.components.zeroconf import ZeroconfServiceInfo


class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
"""Config flow for Awair."""
Expand All @@ -29,7 +32,7 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
host: str

async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
self, discovery_info: ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Handle zeroconf discovery."""

Expand Down
12 changes: 8 additions & 4 deletions homeassistant/components/axis/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from collections.abc import Mapping
from ipaddress import ip_address
from types import MappingProxyType
from typing import Any
from typing import TYPE_CHECKING, Any
from urllib.parse import urlsplit

import voluptuous as vol

from homeassistant.components import dhcp, ssdp, zeroconf
from homeassistant.components import ssdp
from homeassistant.config_entries import (
SOURCE_IGNORE,
SOURCE_REAUTH,
Expand Down Expand Up @@ -46,6 +46,10 @@
from .errors import AuthenticationRequired, CannotConnect
from .hub import AxisHub, get_axis_api

if TYPE_CHECKING:
from homeassistant.components.dhcp import DhcpServiceInfo
from homeassistant.components.zeroconf import ZeroconfServiceInfo

AXIS_OUI = {"00:40:8c", "ac:cc:8e", "b8:a4:4f"}
DEFAULT_PORT = 443
DEFAULT_PROTOCOL = "https"
Expand Down Expand Up @@ -190,7 +194,7 @@ async def _redo_configuration(
return await self.async_step_user()

async def async_step_dhcp(
self, discovery_info: dhcp.DhcpServiceInfo
self, discovery_info: DhcpServiceInfo
) -> ConfigFlowResult:
"""Prepare configuration for a DHCP discovered Axis device."""
return await self._process_discovered_device(
Expand All @@ -217,7 +221,7 @@ async def async_step_ssdp(
)

async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
self, discovery_info: ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Prepare configuration for a Zeroconf discovered Axis device."""
return await self._process_discovered_device(
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/baf/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

from asyncio import timeout
import logging
from typing import Any
from typing import TYPE_CHECKING, Any

from aiobafi6 import Device, Service
from aiobafi6.discovery import PORT
import voluptuous as vol

from homeassistant.components import zeroconf
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_IP_ADDRESS

from .const import DOMAIN, RUN_TIMEOUT
from .models import BAFDiscovery

if TYPE_CHECKING:
from homeassistant.components.zeroconf import ZeroconfServiceInfo

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -44,7 +46,7 @@ def __init__(self) -> None:
self.discovery: BAFDiscovery | None = None

async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
self, discovery_info: ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Handle zeroconf discovery."""
if discovery_info.ip_address.version == 6:
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/bang_olufsen/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from __future__ import annotations

from ipaddress import AddressValueError, IPv4Address
from typing import Any, TypedDict
from typing import TYPE_CHECKING, Any, TypedDict

from aiohttp.client_exceptions import ClientConnectorError
from mozart_api.exceptions import ApiException
from mozart_api.mozart_client import MozartClient
import voluptuous as vol

from homeassistant.components.zeroconf import ZeroconfServiceInfo
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_MODEL
from homeassistant.helpers.selector import SelectSelector, SelectSelectorConfig
Expand All @@ -28,6 +27,9 @@
)
from .util import get_serial_number_from_jid

if TYPE_CHECKING:
from homeassistant.components.zeroconf import ZeroconfServiceInfo


class EntryData(TypedDict, total=False):
"""TypedDict for config_entry data."""
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/blebox/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import logging
from typing import Any
from typing import TYPE_CHECKING, Any

from blebox_uniapi.box import Box
from blebox_uniapi.error import (
Expand All @@ -15,7 +15,6 @@
from blebox_uniapi.session import ApiHost
import voluptuous as vol

from homeassistant.components import zeroconf
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand All @@ -32,6 +31,9 @@
UNSUPPORTED_VERSION,
)

if TYPE_CHECKING:
from homeassistant.components.zeroconf import ZeroconfServiceInfo

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -84,7 +86,7 @@ def handle_step_exception(
)

async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
self, discovery_info: ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Handle zeroconf discovery."""
hass = self.hass
Expand Down
10 changes: 7 additions & 3 deletions homeassistant/components/bluesound/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Config flow for bluesound."""

from __future__ import annotations

import logging
from typing import Any
from typing import TYPE_CHECKING, Any

from pyblu import Player, SyncStatus
from pyblu.errors import PlayerUnreachableError
import voluptuous as vol

from homeassistant.components import zeroconf
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand All @@ -16,6 +17,9 @@
from .media_player import DEFAULT_PORT
from .utils import format_unique_id

if TYPE_CHECKING:
from homeassistant.components.zeroconf import ZeroconfServiceInfo

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -72,7 +76,7 @@ async def async_step_user(
)

async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
self, discovery_info: ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Handle a flow initialized by zeroconf discovery."""
if discovery_info.port is not None:
Expand Down
8 changes: 5 additions & 3 deletions homeassistant/components/bond/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import contextlib
from http import HTTPStatus
import logging
from typing import Any
from typing import TYPE_CHECKING, Any

from aiohttp import ClientConnectionError, ClientResponseError
from bond_async import Bond
import voluptuous as vol

from homeassistant.components import zeroconf
from homeassistant.config_entries import ConfigEntryState, ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, CONF_NAME
from homeassistant.core import HomeAssistant
Expand All @@ -21,6 +20,9 @@
from .const import DOMAIN
from .utils import BondHub

if TYPE_CHECKING:
from homeassistant.components.zeroconf import ZeroconfServiceInfo

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -97,7 +99,7 @@ async def _async_try_automatic_configure(self) -> None:
self._discovered[CONF_NAME] = hub_name

async def async_step_zeroconf(
self, discovery_info: zeroconf.ZeroconfServiceInfo
self, discovery_info: ZeroconfServiceInfo
) -> ConfigFlowResult:
"""Handle a flow initialized by zeroconf discovery."""
name: str = discovery_info.name
Expand Down
10 changes: 7 additions & 3 deletions homeassistant/components/broadlink/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Config flow for Broadlink devices."""

from __future__ import annotations

from collections.abc import Mapping
import errno
from functools import partial
import logging
import socket
from typing import Any
from typing import TYPE_CHECKING, Any

import broadlink as blk
from broadlink.exceptions import (
Expand All @@ -15,7 +17,6 @@
)
import voluptuous as vol

from homeassistant.components import dhcp
from homeassistant.config_entries import (
SOURCE_IMPORT,
SOURCE_REAUTH,
Expand All @@ -29,6 +30,9 @@
from .const import DEFAULT_PORT, DEFAULT_TIMEOUT, DEVICE_TYPES, DOMAIN
from .helpers import format_mac

if TYPE_CHECKING:
from homeassistant.components.dhcp import DhcpServiceInfo

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -65,7 +69,7 @@ async def async_set_device(
}

async def async_step_dhcp(
self, discovery_info: dhcp.DhcpServiceInfo
self, discovery_info: DhcpServiceInfo
) -> ConfigFlowResult:
"""Handle dhcp discovery."""
host = discovery_info.ip
Expand Down
Loading
Loading