From 223a41419a693099ad5a6f6fecdb764da3ef8d8e Mon Sep 17 00:00:00 2001 From: epenet Date: Wed, 10 Nov 2021 15:40:51 +0000 Subject: [PATCH 01/22] Adjust async_step_zeroconf signature --- homeassistant/config_entries.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 17f8b1396edee8..afe160ae9182d6 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -12,6 +12,7 @@ import weakref from homeassistant import data_entry_flow, loader +from homeassistant.components.zeroconf import ZeroconfServiceInfo from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP from homeassistant.core import CALLBACK_TYPE, CoreState, HomeAssistant, callback from homeassistant.exceptions import ( @@ -1369,10 +1370,10 @@ async def async_step_ssdp( return await self.async_step_discovery(discovery_info) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: ZeroconfServiceInfo ) -> data_entry_flow.FlowResult: """Handle a flow initialized by Zeroconf discovery.""" - return await self.async_step_discovery(discovery_info) + return await self.async_step_discovery(cast(DiscoveryInfoType, discovery_info)) async def async_step_dhcp( self, discovery_info: DiscoveryInfoType From 53a1124a696138c5e7f763b851b5138cf5b71856 Mon Sep 17 00:00:00 2001 From: epenet Date: Wed, 10 Nov 2021 16:06:36 +0000 Subject: [PATCH 02/22] Adjust signature in components --- homeassistant/components/apple_tv/config_flow.py | 3 +-- homeassistant/components/bond/config_flow.py | 3 +-- homeassistant/components/brother/config_flow.py | 3 +-- homeassistant/components/cast/config_flow.py | 4 ++-- homeassistant/components/daikin/config_flow.py | 3 +-- .../components/devolo_home_control/config_flow.py | 3 +-- homeassistant/components/elgato/config_flow.py | 5 ++++- homeassistant/components/esphome/config_flow.py | 3 +-- homeassistant/components/guardian/config_flow.py | 3 ++- homeassistant/components/lookin/config_flow.py | 4 ++-- homeassistant/components/modern_forms/config_flow.py | 8 ++++---- homeassistant/components/nam/config_flow.py | 4 ++-- homeassistant/components/nanoleaf/config_flow.py | 3 ++- homeassistant/components/rainmachine/config_flow.py | 3 ++- homeassistant/components/shelly/config_flow.py | 4 ++-- homeassistant/components/sonos/config_flow.py | 4 ++-- homeassistant/components/system_bridge/config_flow.py | 4 ++-- homeassistant/components/volumio/config_flow.py | 4 ++-- homeassistant/components/wled/config_flow.py | 8 ++++---- 19 files changed, 38 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/apple_tv/config_flow.py b/homeassistant/components/apple_tv/config_flow.py index f1a89688ad4087..306a1d9f793697 100644 --- a/homeassistant/components/apple_tv/config_flow.py +++ b/homeassistant/components/apple_tv/config_flow.py @@ -15,7 +15,6 @@ from homeassistant.data_entry_flow import AbortFlow, FlowResult from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.typing import DiscoveryInfoType from .const import CONF_CREDENTIALS, CONF_IDENTIFIER, CONF_START_OFF, DOMAIN @@ -145,7 +144,7 @@ async def async_step_user(self, user_input=None): ) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle device found via zeroconf.""" service_type = discovery_info[zeroconf.ATTR_TYPE] diff --git a/homeassistant/components/bond/config_flow.py b/homeassistant/components/bond/config_flow.py index 5996cd03baed1a..d9398edf2c92ea 100644 --- a/homeassistant/components/bond/config_flow.py +++ b/homeassistant/components/bond/config_flow.py @@ -16,7 +16,6 @@ from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import AbortFlow, FlowResult from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.typing import DiscoveryInfoType from .const import DOMAIN from .utils import BondHub @@ -92,7 +91,7 @@ async def _async_try_automatic_configure(self) -> None: self._discovered[CONF_NAME] = hub_name async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle a flow initialized by zeroconf discovery.""" name: str = discovery_info[zeroconf.ATTR_NAME] diff --git a/homeassistant/components/brother/config_flow.py b/homeassistant/components/brother/config_flow.py index fa743e68d56ae6..cd281208506a16 100644 --- a/homeassistant/components/brother/config_flow.py +++ b/homeassistant/components/brother/config_flow.py @@ -12,7 +12,6 @@ from homeassistant.components import zeroconf from homeassistant.const import CONF_HOST, CONF_TYPE from homeassistant.data_entry_flow import FlowResult -from homeassistant.helpers.typing import DiscoveryInfoType from .const import DOMAIN, PRINTER_TYPES from .utils import get_snmp_engine @@ -81,7 +80,7 @@ async def async_step_user( ) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" # Hostname is format: brother.local. diff --git a/homeassistant/components/cast/config_flow.py b/homeassistant/components/cast/config_flow.py index dbf52a8f238e21..aaf8d5b9c6c94c 100644 --- a/homeassistant/components/cast/config_flow.py +++ b/homeassistant/components/cast/config_flow.py @@ -2,9 +2,9 @@ import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers import config_validation as cv -from homeassistant.helpers.typing import DiscoveryInfoType from .const import CONF_IGNORE_CEC, CONF_KNOWN_HOSTS, CONF_UUID, DOMAIN @@ -52,7 +52,7 @@ async def async_step_user(self, user_input=None): return await self.async_step_config() async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle a flow initialized by zeroconf discovery.""" if self._async_in_progress() or self._async_current_entries(): diff --git a/homeassistant/components/daikin/config_flow.py b/homeassistant/components/daikin/config_flow.py index 89b27b68c81229..e907aaa4d74985 100644 --- a/homeassistant/components/daikin/config_flow.py +++ b/homeassistant/components/daikin/config_flow.py @@ -13,7 +13,6 @@ from homeassistant.components import zeroconf from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD from homeassistant.data_entry_flow import FlowResult -from homeassistant.helpers.typing import DiscoveryInfoType from .const import CONF_UUID, DOMAIN, KEY_MAC, TIMEOUT @@ -127,7 +126,7 @@ async def async_step_user(self, user_input=None): ) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Prepare configuration for a discovered Daikin device.""" _LOGGER.debug("Zeroconf user_input: %s", discovery_info) diff --git a/homeassistant/components/devolo_home_control/config_flow.py b/homeassistant/components/devolo_home_control/config_flow.py index 0cff72a4321222..693aeb187b18d4 100644 --- a/homeassistant/components/devolo_home_control/config_flow.py +++ b/homeassistant/components/devolo_home_control/config_flow.py @@ -11,7 +11,6 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult -from homeassistant.helpers.typing import DiscoveryInfoType from . import configure_mydevolo from .const import CONF_MYDEVOLO, DEFAULT_MYDEVOLO, DOMAIN, SUPPORTED_MODEL_TYPES @@ -46,7 +45,7 @@ async def async_step_user( return self._show_form(step_id="user", errors={"base": "invalid_auth"}) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" # Check if it is a gateway diff --git a/homeassistant/components/elgato/config_flow.py b/homeassistant/components/elgato/config_flow.py index 6008ccbee7780d..4d38caf0fab7e3 100644 --- a/homeassistant/components/elgato/config_flow.py +++ b/homeassistant/components/elgato/config_flow.py @@ -6,6 +6,7 @@ from elgato import Elgato, ElgatoError import voluptuous as vol +from homeassistant.components import zeroconf from homeassistant.config_entries import ConfigFlow from homeassistant.const import CONF_HOST, CONF_PORT from homeassistant.core import callback @@ -41,7 +42,9 @@ async def async_step_user( return self._async_create_entry() - async def async_step_zeroconf(self, discovery_info: dict[str, Any]) -> FlowResult: + async def async_step_zeroconf( + self, discovery_info: zeroconf.ZeroconfServiceInfo + ) -> FlowResult: """Handle zeroconf discovery.""" self.host = discovery_info[CONF_HOST] self.port = discovery_info[CONF_PORT] diff --git a/homeassistant/components/esphome/config_flow.py b/homeassistant/components/esphome/config_flow.py index a794404b685253..fa72cbd995ebdd 100644 --- a/homeassistant/components/esphome/config_flow.py +++ b/homeassistant/components/esphome/config_flow.py @@ -20,7 +20,6 @@ from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_PORT from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult -from homeassistant.helpers.typing import DiscoveryInfoType from . import CONF_NOISE_PSK, DOMAIN, DomainData @@ -139,7 +138,7 @@ async def async_step_discovery_confirm( ) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" # Hostname is format: livingroom.local. diff --git a/homeassistant/components/guardian/config_flow.py b/homeassistant/components/guardian/config_flow.py index ccebeb996759e3..452574d4eed679 100644 --- a/homeassistant/components/guardian/config_flow.py +++ b/homeassistant/components/guardian/config_flow.py @@ -8,6 +8,7 @@ import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.components.dhcp import IP_ADDRESS from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT from homeassistant.core import HomeAssistant, callback @@ -107,7 +108,7 @@ async def async_step_dhcp(self, discovery_info: DiscoveryInfoType) -> FlowResult return await self._async_handle_discovery() async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle the configuration via zeroconf.""" self.discovery_info = { diff --git a/homeassistant/components/lookin/config_flow.py b/homeassistant/components/lookin/config_flow.py index 14e4b517b5b7a0..e41aad0406b01c 100644 --- a/homeassistant/components/lookin/config_flow.py +++ b/homeassistant/components/lookin/config_flow.py @@ -9,10 +9,10 @@ import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.const import CONF_HOST from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.typing import DiscoveryInfoType from .const import DOMAIN @@ -28,7 +28,7 @@ def __init__(self) -> None: self._name: str | None = None async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Start a discovery flow from zeroconf.""" uid: str = discovery_info["hostname"][: -len(".local.")] diff --git a/homeassistant/components/modern_forms/config_flow.py b/homeassistant/components/modern_forms/config_flow.py index e8b557f7bc5d83..147976ee2b04db 100644 --- a/homeassistant/components/modern_forms/config_flow.py +++ b/homeassistant/components/modern_forms/config_flow.py @@ -1,16 +1,16 @@ """Config flow for Modern Forms.""" from __future__ import annotations -from typing import Any +from typing import Any, cast from aiomodernforms import ModernFormsConnectionError, ModernFormsDevice import voluptuous as vol +from homeassistant.components import zeroconf from homeassistant.config_entries import SOURCE_ZEROCONF, ConfigFlow from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.typing import DiscoveryInfoType from .const import DOMAIN @@ -27,7 +27,7 @@ async def async_step_user( return await self._handle_config_flow(user_input) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" host = discovery_info["hostname"].rstrip(".") @@ -43,7 +43,7 @@ async def async_step_zeroconf( ) # Prepare configuration flow - return await self._handle_config_flow(discovery_info, True) + return await self._handle_config_flow(cast(dict, discovery_info), True) async def async_step_zeroconf_confirm( self, user_input: dict[str, Any] | None = None diff --git a/homeassistant/components/nam/config_flow.py b/homeassistant/components/nam/config_flow.py index 0fe2c8f9c652f4..2d74d3529d44e4 100644 --- a/homeassistant/components/nam/config_flow.py +++ b/homeassistant/components/nam/config_flow.py @@ -11,11 +11,11 @@ import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.const import ATTR_NAME, CONF_HOST from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import format_mac -from homeassistant.helpers.typing import DiscoveryInfoType from .const import DOMAIN @@ -69,7 +69,7 @@ async def async_step_user( ) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" self.host = discovery_info[CONF_HOST] diff --git a/homeassistant/components/nanoleaf/config_flow.py b/homeassistant/components/nanoleaf/config_flow.py index 0f4f8ff75bdf6b..5de3eac9c072fa 100644 --- a/homeassistant/components/nanoleaf/config_flow.py +++ b/homeassistant/components/nanoleaf/config_flow.py @@ -9,6 +9,7 @@ import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.const import CONF_HOST, CONF_TOKEN from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -88,7 +89,7 @@ async def async_step_reauth(self, data: dict[str, str]) -> FlowResult: return await self.async_step_link() async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle Nanoleaf Zeroconf discovery.""" _LOGGER.debug("Zeroconf discovered: %s", discovery_info) diff --git a/homeassistant/components/rainmachine/config_flow.py b/homeassistant/components/rainmachine/config_flow.py index c392ad1f8ce236..f1910dfeb87b9b 100644 --- a/homeassistant/components/rainmachine/config_flow.py +++ b/homeassistant/components/rainmachine/config_flow.py @@ -9,6 +9,7 @@ import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, CONF_PORT, CONF_SSL from homeassistant.core import HomeAssistant, callback @@ -59,7 +60,7 @@ async def async_step_homekit(self, discovery_info: DiscoveryInfoType) -> FlowRes return await self.async_step_zeroconf(discovery_info) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle discovery via zeroconf.""" ip_address = discovery_info["host"] diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index 580221d376ffbf..b7b9ab729767af 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -14,11 +14,11 @@ import voluptuous as vol from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers import aiohttp_client -from homeassistant.helpers.typing import DiscoveryInfoType from .const import AIOSHELLY_DEVICE_TIMEOUT_SEC, CONF_SLEEP_PERIOD, DOMAIN from .utils import ( @@ -186,7 +186,7 @@ async def async_step_credentials( ) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" try: diff --git a/homeassistant/components/sonos/config_flow.py b/homeassistant/components/sonos/config_flow.py index 745d3db3890667..f068fd9d196d01 100644 --- a/homeassistant/components/sonos/config_flow.py +++ b/homeassistant/components/sonos/config_flow.py @@ -2,11 +2,11 @@ import soco from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.const import CONF_HOST, CONF_NAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.config_entry_flow import DiscoveryFlowHandler -from homeassistant.helpers.typing import DiscoveryInfoType from .const import DATA_SONOS_DISCOVERY_MANAGER, DOMAIN from .helpers import hostname_to_uid @@ -26,7 +26,7 @@ def __init__(self) -> None: super().__init__(DOMAIN, "Sonos", _async_has_devices) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle a flow initialized by zeroconf.""" hostname = discovery_info["hostname"] diff --git a/homeassistant/components/system_bridge/config_flow.py b/homeassistant/components/system_bridge/config_flow.py index 4ff887c63897e6..8d0b7a5dfff075 100644 --- a/homeassistant/components/system_bridge/config_flow.py +++ b/homeassistant/components/system_bridge/config_flow.py @@ -11,11 +11,11 @@ import voluptuous as vol from homeassistant import config_entries, exceptions +from homeassistant.components import zeroconf from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers import aiohttp_client, config_validation as cv -from homeassistant.helpers.typing import DiscoveryInfoType from .const import BRIDGE_CONNECTION_ERRORS, DOMAIN @@ -148,7 +148,7 @@ async def async_step_authenticate( ) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" host = discovery_info["properties"].get("ip") diff --git a/homeassistant/components/volumio/config_flow.py b/homeassistant/components/volumio/config_flow.py index 45c424b356e9a0..33b4a7907aa88e 100644 --- a/homeassistant/components/volumio/config_flow.py +++ b/homeassistant/components/volumio/config_flow.py @@ -7,10 +7,10 @@ import voluptuous as vol from homeassistant import config_entries, exceptions +from homeassistant.components import zeroconf from homeassistant.const import CONF_HOST, CONF_ID, CONF_NAME, CONF_PORT from homeassistant.core import callback from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.typing import DiscoveryInfoType from .const import DOMAIN @@ -93,7 +93,7 @@ async def async_step_user(self, user_input=None): step_id="user", data_schema=DATA_SCHEMA, errors=errors ) - async def async_step_zeroconf(self, discovery_info: DiscoveryInfoType): + async def async_step_zeroconf(self, discovery_info: zeroconf.ZeroconfServiceInfo): """Handle zeroconf discovery.""" self._host = discovery_info["host"] self._port = int(discovery_info["port"]) diff --git a/homeassistant/components/wled/config_flow.py b/homeassistant/components/wled/config_flow.py index 7f4d006d1225e5..828dfc3368a866 100644 --- a/homeassistant/components/wled/config_flow.py +++ b/homeassistant/components/wled/config_flow.py @@ -1,11 +1,12 @@ """Config flow to configure the WLED integration.""" from __future__ import annotations -from typing import Any +from typing import Any, cast import voluptuous as vol from wled import WLED, WLEDConnectionError +from homeassistant.components import zeroconf from homeassistant.config_entries import ( SOURCE_ZEROCONF, ConfigEntry, @@ -16,7 +17,6 @@ from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.aiohttp_client import async_get_clientsession -from homeassistant.helpers.typing import DiscoveryInfoType from .const import CONF_KEEP_MASTER_LIGHT, DEFAULT_KEEP_MASTER_LIGHT, DOMAIN @@ -39,7 +39,7 @@ async def async_step_user( return await self._handle_config_flow(user_input) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zeroconf discovery.""" @@ -57,7 +57,7 @@ async def async_step_zeroconf( ) # Prepare configuration flow - return await self._handle_config_flow(discovery_info, True) + return await self._handle_config_flow(cast(dict, discovery_info), True) async def async_step_zeroconf_confirm( self, user_input: dict[str, Any] | None = None From 6b5d0f8109c0d772d347d0452d1614ee8d7baa15 Mon Sep 17 00:00:00 2001 From: epenet Date: Wed, 10 Nov 2021 16:12:03 +0000 Subject: [PATCH 03/22] Add required cast --- homeassistant/components/brother/config_flow.py | 2 +- .../components/devolo_home_control/config_flow.py | 5 +---- homeassistant/components/nam/config_flow.py | 2 +- homeassistant/components/nanoleaf/config_flow.py | 4 +++- homeassistant/components/rainmachine/config_flow.py | 10 ++++++++-- homeassistant/components/sonos/config_flow.py | 4 +++- homeassistant/components/volumio/config_flow.py | 2 +- 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/brother/config_flow.py b/homeassistant/components/brother/config_flow.py index cd281208506a16..7a814e2e77c184 100644 --- a/homeassistant/components/brother/config_flow.py +++ b/homeassistant/components/brother/config_flow.py @@ -90,7 +90,7 @@ async def async_step_zeroconf( self._async_abort_entries_match({CONF_HOST: self.host}) snmp_engine = get_snmp_engine(self.hass) - model = discovery_info.get(zeroconf.ATTR_PROPERTIES, {}).get("product") + model = discovery_info[zeroconf.ATTR_PROPERTIES].get("product") try: self.brother = Brother(self.host, snmp_engine=snmp_engine, model=model) diff --git a/homeassistant/components/devolo_home_control/config_flow.py b/homeassistant/components/devolo_home_control/config_flow.py index 693aeb187b18d4..fab5c2b5008481 100644 --- a/homeassistant/components/devolo_home_control/config_flow.py +++ b/homeassistant/components/devolo_home_control/config_flow.py @@ -49,10 +49,7 @@ async def async_step_zeroconf( ) -> FlowResult: """Handle zeroconf discovery.""" # Check if it is a gateway - if ( - discovery_info.get(zeroconf.ATTR_PROPERTIES, {}).get("MT") - in SUPPORTED_MODEL_TYPES - ): + if discovery_info[zeroconf.ATTR_PROPERTIES].get("MT") in SUPPORTED_MODEL_TYPES: await self._async_handle_discovery_without_unique_id() return await self.async_step_zeroconf_confirm() return self.async_abort(reason="Not a devolo Home Control gateway.") diff --git a/homeassistant/components/nam/config_flow.py b/homeassistant/components/nam/config_flow.py index 2d74d3529d44e4..86a30f95af6e6f 100644 --- a/homeassistant/components/nam/config_flow.py +++ b/homeassistant/components/nam/config_flow.py @@ -78,7 +78,7 @@ async def async_step_zeroconf( self._async_abort_entries_match({CONF_HOST: self.host}) try: - mac = await self._async_get_mac(cast(str, self.host)) + mac = await self._async_get_mac(self.host) except (ApiError, ClientConnectorError, asyncio.TimeoutError): return self.async_abort(reason="cannot_connect") except CannotGetMac: diff --git a/homeassistant/components/nanoleaf/config_flow.py b/homeassistant/components/nanoleaf/config_flow.py index 5de3eac9c072fa..17269f2e07ad46 100644 --- a/homeassistant/components/nanoleaf/config_flow.py +++ b/homeassistant/components/nanoleaf/config_flow.py @@ -93,7 +93,9 @@ async def async_step_zeroconf( ) -> FlowResult: """Handle Nanoleaf Zeroconf discovery.""" _LOGGER.debug("Zeroconf discovered: %s", discovery_info) - return await self._async_homekit_zeroconf_discovery_handler(discovery_info) + return await self._async_homekit_zeroconf_discovery_handler( + cast(dict, discovery_info) + ) async def async_step_homekit(self, discovery_info: DiscoveryInfoType) -> FlowResult: """Handle Nanoleaf Homekit discovery.""" diff --git a/homeassistant/components/rainmachine/config_flow.py b/homeassistant/components/rainmachine/config_flow.py index f1910dfeb87b9b..47896cc60804e8 100644 --- a/homeassistant/components/rainmachine/config_flow.py +++ b/homeassistant/components/rainmachine/config_flow.py @@ -1,7 +1,7 @@ """Config flow to configure the RainMachine component.""" from __future__ import annotations -from typing import Any +from typing import Any, cast from regenmaschine import Client from regenmaschine.controller import Controller @@ -57,10 +57,16 @@ def async_get_options_flow( async def async_step_homekit(self, discovery_info: DiscoveryInfoType) -> FlowResult: """Handle a flow initialized by homekit discovery.""" - return await self.async_step_zeroconf(discovery_info) + return await self.async_step_homekit_zeroconf(discovery_info) async def async_step_zeroconf( self, discovery_info: zeroconf.ZeroconfServiceInfo + ) -> FlowResult: + """Handle discovery via zeroconf.""" + return await self.async_step_homekit_zeroconf(cast(dict, discovery_info)) + + async def async_step_homekit_zeroconf( + self, discovery_info: DiscoveryInfoType ) -> FlowResult: """Handle discovery via zeroconf.""" ip_address = discovery_info["host"] diff --git a/homeassistant/components/sonos/config_flow.py b/homeassistant/components/sonos/config_flow.py index f068fd9d196d01..a4f6b87fafca12 100644 --- a/homeassistant/components/sonos/config_flow.py +++ b/homeassistant/components/sonos/config_flow.py @@ -1,4 +1,6 @@ """Config flow for SONOS.""" +from typing import cast + import soco from homeassistant import config_entries @@ -43,7 +45,7 @@ async def async_step_zeroconf( discovery_manager.async_discovered_player( "Zeroconf", properties, host, uid, boot_seqnum, model, mdns_name ) - return await self.async_step_discovery(discovery_info) + return await self.async_step_discovery(cast(dict, discovery_info)) config_entries.HANDLERS.register(DOMAIN)(SonosDiscoveryFlowHandler) diff --git a/homeassistant/components/volumio/config_flow.py b/homeassistant/components/volumio/config_flow.py index 33b4a7907aa88e..a499b7827b5aa2 100644 --- a/homeassistant/components/volumio/config_flow.py +++ b/homeassistant/components/volumio/config_flow.py @@ -96,7 +96,7 @@ async def async_step_user(self, user_input=None): async def async_step_zeroconf(self, discovery_info: zeroconf.ZeroconfServiceInfo): """Handle zeroconf discovery.""" self._host = discovery_info["host"] - self._port = int(discovery_info["port"]) + self._port = discovery_info["port"] self._name = discovery_info["properties"]["volumioName"] self._uuid = discovery_info["properties"]["UUID"] From 5571823764fa95673209aaa803ec4ea2070267fb Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 08:42:40 +0000 Subject: [PATCH 04/22] Fix brother tests --- tests/components/brother/test_config_flow.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/components/brother/test_config_flow.py b/tests/components/brother/test_config_flow.py index 314748e5cded2f..85bc49e484e713 100644 --- a/tests/components/brother/test_config_flow.py +++ b/tests/components/brother/test_config_flow.py @@ -13,6 +13,9 @@ from tests.common import MockConfigEntry, load_fixture CONFIG = {CONF_HOST: "localhost", CONF_TYPE: "laser"} +ZEROCONF_CONFIG = zeroconf.ZeroconfServiceInfo( + hostname="example.local.", name="Brother Printer", properties={} +) async def test_show_form(hass): @@ -144,9 +147,7 @@ async def test_zeroconf_snmp_error(hass): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, - data=zeroconf.ZeroconfServiceInfo( - hostname="example.local.", name="Brother Printer" - ), + data=ZEROCONF_CONFIG, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT @@ -184,9 +185,7 @@ async def test_zeroconf_device_exists_abort(hass): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, - data=zeroconf.ZeroconfServiceInfo( - hostname="example.local.", name="Brother Printer" - ), + data=ZEROCONF_CONFIG, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT @@ -222,9 +221,7 @@ async def test_zeroconf_confirm_create_entry(hass): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, - data=zeroconf.ZeroconfServiceInfo( - hostname="example.local.", name="Brother Printer" - ), + data=ZEROCONF_CONFIG, ) assert result["step_id"] == "zeroconf_confirm" From dea01d8a714a69d561d60786125eac9f05a92a6f Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 09:07:55 +0000 Subject: [PATCH 05/22] Add type ignore for elgato --- homeassistant/components/elgato/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/elgato/config_flow.py b/homeassistant/components/elgato/config_flow.py index 4d38caf0fab7e3..5a64a0b8d7d987 100644 --- a/homeassistant/components/elgato/config_flow.py +++ b/homeassistant/components/elgato/config_flow.py @@ -47,7 +47,7 @@ async def async_step_zeroconf( ) -> FlowResult: """Handle zeroconf discovery.""" self.host = discovery_info[CONF_HOST] - self.port = discovery_info[CONF_PORT] + self.port = discovery_info[CONF_PORT] # type: ignore [assignment] try: await self._get_elgato_serial_number() From 8a4575c461b5d21c759d5a57670b2851e2369a6c Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 09:09:15 +0000 Subject: [PATCH 06/22] Use ZeroconfServiceInfo on devolo_home_network --- homeassistant/components/devolo_home_network/config_flow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/devolo_home_network/config_flow.py b/homeassistant/components/devolo_home_network/config_flow.py index 20efe388407940..c3e91a6ec65bb7 100644 --- a/homeassistant/components/devolo_home_network/config_flow.py +++ b/homeassistant/components/devolo_home_network/config_flow.py @@ -13,7 +13,7 @@ from homeassistant.const import CONF_HOST, CONF_IP_ADDRESS, CONF_NAME from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.httpx_client import get_async_client -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType +from homeassistant.helpers.typing import ConfigType from .const import DOMAIN, PRODUCT, SERIAL_NUMBER, TITLE @@ -74,7 +74,7 @@ async def async_step_user(self, user_input: ConfigType | None = None) -> FlowRes ) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle zerooconf discovery.""" if discovery_info[zeroconf.ATTR_PROPERTIES]["MT"] in ["2600", "2601"]: From d2f8eae78592b4451c2f7413781cb6a3c8179032 Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 09:33:09 +0000 Subject: [PATCH 07/22] Use ZeroconfServiceInfo on axis --- homeassistant/components/axis/config_flow.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/axis/config_flow.py b/homeassistant/components/axis/config_flow.py index e3994cedd39dcb..d1e834e7bb6d50 100644 --- a/homeassistant/components/axis/config_flow.py +++ b/homeassistant/components/axis/config_flow.py @@ -20,7 +20,6 @@ from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.device_registry import format_mac -from homeassistant.helpers.typing import DiscoveryInfoType from homeassistant.util.network import is_link_local from .const import ( @@ -178,7 +177,7 @@ async def async_step_ssdp(self, discovery_info: dict): ) async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Prepare configuration for a Zeroconf discovered Axis device.""" return await self._process_discovered_device( From e54096b2e7660f567d0b10affc10dde57977db56 Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 09:34:04 +0000 Subject: [PATCH 08/22] Use ZeroconfServiceInfo on hue --- homeassistant/components/hue/config_flow.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/hue/config_flow.py b/homeassistant/components/hue/config_flow.py index 409f88cbe04c74..0ffa7e358f07ee 100644 --- a/homeassistant/components/hue/config_flow.py +++ b/homeassistant/components/hue/config_flow.py @@ -16,7 +16,6 @@ from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers import aiohttp_client -from homeassistant.helpers.typing import DiscoveryInfoType from .bridge import authenticate_bridge from .const import ( @@ -209,7 +208,7 @@ async def async_step_ssdp(self, discovery_info): return await self.async_step_link() async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle a discovered Hue bridge. From 3b1f3e31e367398a270be0cb39042c6247f027cf Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 09:34:48 +0000 Subject: [PATCH 09/22] Use ZeroconfServiceInfo on modern_forms --- homeassistant/components/modern_forms/config_flow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/modern_forms/config_flow.py b/homeassistant/components/modern_forms/config_flow.py index 147976ee2b04db..5439a57f90dbfb 100644 --- a/homeassistant/components/modern_forms/config_flow.py +++ b/homeassistant/components/modern_forms/config_flow.py @@ -1,7 +1,7 @@ """Config flow for Modern Forms.""" from __future__ import annotations -from typing import Any, cast +from typing import Any from aiomodernforms import ModernFormsConnectionError, ModernFormsDevice import voluptuous as vol @@ -43,7 +43,7 @@ async def async_step_zeroconf( ) # Prepare configuration flow - return await self._handle_config_flow(cast(dict, discovery_info), True) + return await self._handle_config_flow(discovery_info.__dict__, True) async def async_step_zeroconf_confirm( self, user_input: dict[str, Any] | None = None From c8028cd10baedf3f9f93ac453a715d07d157d93d Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 09:35:06 +0000 Subject: [PATCH 10/22] Use ZeroconfServiceInfo on nanoleaf --- homeassistant/components/nanoleaf/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/nanoleaf/config_flow.py b/homeassistant/components/nanoleaf/config_flow.py index 17269f2e07ad46..8b31d5dcb07f3f 100644 --- a/homeassistant/components/nanoleaf/config_flow.py +++ b/homeassistant/components/nanoleaf/config_flow.py @@ -94,7 +94,7 @@ async def async_step_zeroconf( """Handle Nanoleaf Zeroconf discovery.""" _LOGGER.debug("Zeroconf discovered: %s", discovery_info) return await self._async_homekit_zeroconf_discovery_handler( - cast(dict, discovery_info) + discovery_info.__dict__ ) async def async_step_homekit(self, discovery_info: DiscoveryInfoType) -> FlowResult: From d3d5ddd1a712c15745b69fa6d5fb37497bbbbf8d Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 09:36:21 +0000 Subject: [PATCH 11/22] Use ZeroconfServiceInfo on samsungtv --- homeassistant/components/samsungtv/config_flow.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/samsungtv/config_flow.py b/homeassistant/components/samsungtv/config_flow.py index c75086322daacf..1525d037cd96bd 100644 --- a/homeassistant/components/samsungtv/config_flow.py +++ b/homeassistant/components/samsungtv/config_flow.py @@ -10,6 +10,7 @@ import voluptuous as vol from homeassistant import config_entries, data_entry_flow +from homeassistant.components import zeroconf from homeassistant.components.dhcp import IP_ADDRESS, MAC_ADDRESS from homeassistant.components.ssdp import ( ATTR_SSDP_LOCATION, @@ -37,7 +38,6 @@ mac_from_device_info, ) from .const import ( - ATTR_PROPERTIES, CONF_MANUFACTURER, CONF_MODEL, DEFAULT_MANUFACTURER, @@ -297,12 +297,12 @@ async def async_step_dhcp( return await self.async_step_confirm() async def async_step_zeroconf( - self, discovery_info: DiscoveryInfoType + self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> data_entry_flow.FlowResult: """Handle a flow initialized by zeroconf discovery.""" LOGGER.debug("Samsung device found via ZEROCONF: %s", discovery_info) - self._mac = format_mac(discovery_info[ATTR_PROPERTIES]["deviceid"]) - self._host = discovery_info[CONF_HOST] + self._mac = format_mac(discovery_info[zeroconf.ATTR_PROPERTIES]["deviceid"]) + self._host = discovery_info[zeroconf.ATTR_HOST] await self._async_start_discovery_with_mac_address() await self._async_set_device_unique_id() self.context["title_placeholders"] = {"device": self._title} From 71735c6b912800b0082144b025f4c5b73ad24b96 Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 09:37:01 +0000 Subject: [PATCH 12/22] Drop cast in async_step_zeroconf --- homeassistant/config_entries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index afe160ae9182d6..8e68c360126953 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -1373,7 +1373,7 @@ async def async_step_zeroconf( self, discovery_info: ZeroconfServiceInfo ) -> data_entry_flow.FlowResult: """Handle a flow initialized by Zeroconf discovery.""" - return await self.async_step_discovery(cast(DiscoveryInfoType, discovery_info)) + return await self.async_step_discovery(discovery_info.__dict__) async def async_step_dhcp( self, discovery_info: DiscoveryInfoType From 0b0eded0f4956d5cd1eeac35d8018429e17a2391 Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 09:38:39 +0000 Subject: [PATCH 13/22] Remove zeroconf reference in DiscoveryFlowHandler --- homeassistant/helpers/config_entry_flow.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/helpers/config_entry_flow.py b/homeassistant/helpers/config_entry_flow.py index 2f9f0b52839f29..cebb011386dc75 100644 --- a/homeassistant/helpers/config_entry_flow.py +++ b/homeassistant/helpers/config_entry_flow.py @@ -81,7 +81,6 @@ async def async_step_discovery( return await self.async_step_confirm() - async_step_zeroconf = async_step_discovery async_step_ssdp = async_step_discovery async_step_mqtt = async_step_discovery async_step_homekit = async_step_discovery From d724ac421828c403c94ac7e783fc684406a328b4 Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 13:10:47 +0000 Subject: [PATCH 14/22] Fix cast issues --- homeassistant/components/modern_forms/config_flow.py | 4 ++-- homeassistant/components/nanoleaf/config_flow.py | 2 +- homeassistant/config_entries.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/modern_forms/config_flow.py b/homeassistant/components/modern_forms/config_flow.py index 5439a57f90dbfb..147976ee2b04db 100644 --- a/homeassistant/components/modern_forms/config_flow.py +++ b/homeassistant/components/modern_forms/config_flow.py @@ -1,7 +1,7 @@ """Config flow for Modern Forms.""" from __future__ import annotations -from typing import Any +from typing import Any, cast from aiomodernforms import ModernFormsConnectionError, ModernFormsDevice import voluptuous as vol @@ -43,7 +43,7 @@ async def async_step_zeroconf( ) # Prepare configuration flow - return await self._handle_config_flow(discovery_info.__dict__, True) + return await self._handle_config_flow(cast(dict, discovery_info), True) async def async_step_zeroconf_confirm( self, user_input: dict[str, Any] | None = None diff --git a/homeassistant/components/nanoleaf/config_flow.py b/homeassistant/components/nanoleaf/config_flow.py index 8b31d5dcb07f3f..17269f2e07ad46 100644 --- a/homeassistant/components/nanoleaf/config_flow.py +++ b/homeassistant/components/nanoleaf/config_flow.py @@ -94,7 +94,7 @@ async def async_step_zeroconf( """Handle Nanoleaf Zeroconf discovery.""" _LOGGER.debug("Zeroconf discovered: %s", discovery_info) return await self._async_homekit_zeroconf_discovery_handler( - discovery_info.__dict__ + cast(dict, discovery_info) ) async def async_step_homekit(self, discovery_info: DiscoveryInfoType) -> FlowResult: diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 8e68c360126953..ba49b88e50c98e 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -1373,7 +1373,7 @@ async def async_step_zeroconf( self, discovery_info: ZeroconfServiceInfo ) -> data_entry_flow.FlowResult: """Handle a flow initialized by Zeroconf discovery.""" - return await self.async_step_discovery(discovery_info.__dict__) + return await self.async_step_discovery(cast(dict, discovery_info)) async def async_step_dhcp( self, discovery_info: DiscoveryInfoType From 5fd29b8fa5695ac057b8603a384b7c019e9dc61f Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 13:50:07 +0000 Subject: [PATCH 15/22] Adjust brother tests --- tests/components/brother/test_config_flow.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/components/brother/test_config_flow.py b/tests/components/brother/test_config_flow.py index 85bc49e484e713..82757fa425a0cf 100644 --- a/tests/components/brother/test_config_flow.py +++ b/tests/components/brother/test_config_flow.py @@ -13,9 +13,6 @@ from tests.common import MockConfigEntry, load_fixture CONFIG = {CONF_HOST: "localhost", CONF_TYPE: "laser"} -ZEROCONF_CONFIG = zeroconf.ZeroconfServiceInfo( - hostname="example.local.", name="Brother Printer", properties={} -) async def test_show_form(hass): @@ -147,7 +144,9 @@ async def test_zeroconf_snmp_error(hass): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, - data=ZEROCONF_CONFIG, + data=zeroconf.ZeroconfServiceInfo( + hostname="example.local.", name="Brother Printer", properties={} + ), ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT @@ -185,7 +184,9 @@ async def test_zeroconf_device_exists_abort(hass): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, - data=ZEROCONF_CONFIG, + data=zeroconf.ZeroconfServiceInfo( + hostname="example.local.", name="Brother Printer", properties={} + ), ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT @@ -221,7 +222,9 @@ async def test_zeroconf_confirm_create_entry(hass): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_ZEROCONF}, - data=ZEROCONF_CONFIG, + data=zeroconf.ZeroconfServiceInfo( + hostname="example.local.", name="Brother Printer", properties={} + ), ) assert result["step_id"] == "zeroconf_confirm" From b32f2f41e8f647cb1ff409d43fd264c1ad28a12f Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 14:01:02 +0000 Subject: [PATCH 16/22] Fixes for script.gen_requirements_all --- homeassistant/config_entries.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index ba49b88e50c98e..90f7bb89475487 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -8,11 +8,13 @@ import functools import logging from types import MappingProxyType, MethodType -from typing import Any, Callable, Optional, cast +from typing import TYPE_CHECKING, Any, Callable, Optional, cast import weakref from homeassistant import data_entry_flow, loader -from homeassistant.components.zeroconf import ZeroconfServiceInfo + +if TYPE_CHECKING: + from homeassistant.components.zeroconf import ZeroconfServiceInfo from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP from homeassistant.core import CALLBACK_TYPE, CoreState, HomeAssistant, callback from homeassistant.exceptions import ( From 87379a781b91aa3265c0d5ca44ee80f0f0c8126b Mon Sep 17 00:00:00 2001 From: epenet Date: Fri, 12 Nov 2021 14:03:30 +0000 Subject: [PATCH 17/22] Reorder imports --- homeassistant/config_entries.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 90f7bb89475487..521fb5d444c73d 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -12,9 +12,6 @@ import weakref from homeassistant import data_entry_flow, loader - -if TYPE_CHECKING: - from homeassistant.components.zeroconf import ZeroconfServiceInfo from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP from homeassistant.core import CALLBACK_TYPE, CoreState, HomeAssistant, callback from homeassistant.exceptions import ( @@ -34,6 +31,9 @@ from homeassistant.util.decorator import Registry import homeassistant.util.uuid as uuid_util +if TYPE_CHECKING: + from homeassistant.components.zeroconf import ZeroconfServiceInfo + _LOGGER = logging.getLogger(__name__) SOURCE_DISCOVERY = "discovery" From 0edf67dedac5a9733bf6e106afdee68b2701c455 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 14 Nov 2021 19:55:16 +0000 Subject: [PATCH 18/22] Update elgato type hint --- homeassistant/components/elgato/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/elgato/config_flow.py b/homeassistant/components/elgato/config_flow.py index 5a64a0b8d7d987..7a4eb7a7519c19 100644 --- a/homeassistant/components/elgato/config_flow.py +++ b/homeassistant/components/elgato/config_flow.py @@ -47,7 +47,7 @@ async def async_step_zeroconf( ) -> FlowResult: """Handle zeroconf discovery.""" self.host = discovery_info[CONF_HOST] - self.port = discovery_info[CONF_PORT] # type: ignore [assignment] + self.port = discovery_info[CONF_PORT] or 9123 try: await self._get_elgato_serial_number() From 4e7d366d09cacff80e2a3a7f7cc985bdf6090907 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 14 Nov 2021 19:58:50 +0000 Subject: [PATCH 19/22] Bring back async_step_zeroconf --- homeassistant/helpers/config_entry_flow.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/homeassistant/helpers/config_entry_flow.py b/homeassistant/helpers/config_entry_flow.py index cebb011386dc75..578d75eb8c04a5 100644 --- a/homeassistant/helpers/config_entry_flow.py +++ b/homeassistant/helpers/config_entry_flow.py @@ -2,9 +2,10 @@ from __future__ import annotations import logging -from typing import Any, Awaitable, Callable, Union +from typing import Any, Awaitable, Callable, Union, cast from homeassistant import config_entries +from homeassistant.components import zeroconf from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers.typing import UNDEFINED, DiscoveryInfoType, UndefinedType @@ -81,6 +82,12 @@ async def async_step_discovery( return await self.async_step_confirm() + async def async_step_zeroconf( + self, discovery_info: zeroconf.ZeroconfServiceInfo + ) -> FlowResult: + """Handle a flow initialized by Zeroconf discovery.""" + return await self.async_step_discovery(cast(dict, discovery_info)) + async_step_ssdp = async_step_discovery async_step_mqtt = async_step_discovery async_step_homekit = async_step_discovery From a20308f313a6216222abad2a938a6c9a3e12f13d Mon Sep 17 00:00:00 2001 From: epenet Date: Mon, 15 Nov 2021 09:03:57 +0000 Subject: [PATCH 20/22] Remove await from async_step_zeroconf --- homeassistant/helpers/config_entry_flow.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/config_entry_flow.py b/homeassistant/helpers/config_entry_flow.py index 578d75eb8c04a5..8aa89d313960e6 100644 --- a/homeassistant/helpers/config_entry_flow.py +++ b/homeassistant/helpers/config_entry_flow.py @@ -2,7 +2,7 @@ from __future__ import annotations import logging -from typing import Any, Awaitable, Callable, Union, cast +from typing import Any, Awaitable, Callable, Coroutine, Union, cast from homeassistant import config_entries from homeassistant.components import zeroconf @@ -82,11 +82,11 @@ async def async_step_discovery( return await self.async_step_confirm() - async def async_step_zeroconf( + def async_step_zeroconf( self, discovery_info: zeroconf.ZeroconfServiceInfo - ) -> FlowResult: + ) -> Coroutine[Any, Any, FlowResult]: """Handle a flow initialized by Zeroconf discovery.""" - return await self.async_step_discovery(cast(dict, discovery_info)) + return self.async_step_discovery(cast(dict, discovery_info)) async_step_ssdp = async_step_discovery async_step_mqtt = async_step_discovery From fa39f524d27252b8082e84d9d093798c9c5bf1bc Mon Sep 17 00:00:00 2001 From: epenet Date: Mon, 15 Nov 2021 09:33:56 +0000 Subject: [PATCH 21/22] Revert "Remove await from async_step_zeroconf" This reverts commit a20308f313a6216222abad2a938a6c9a3e12f13d. --- homeassistant/helpers/config_entry_flow.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/config_entry_flow.py b/homeassistant/helpers/config_entry_flow.py index 8aa89d313960e6..578d75eb8c04a5 100644 --- a/homeassistant/helpers/config_entry_flow.py +++ b/homeassistant/helpers/config_entry_flow.py @@ -2,7 +2,7 @@ from __future__ import annotations import logging -from typing import Any, Awaitable, Callable, Coroutine, Union, cast +from typing import Any, Awaitable, Callable, Union, cast from homeassistant import config_entries from homeassistant.components import zeroconf @@ -82,11 +82,11 @@ async def async_step_discovery( return await self.async_step_confirm() - def async_step_zeroconf( + async def async_step_zeroconf( self, discovery_info: zeroconf.ZeroconfServiceInfo - ) -> Coroutine[Any, Any, FlowResult]: + ) -> FlowResult: """Handle a flow initialized by Zeroconf discovery.""" - return self.async_step_discovery(cast(dict, discovery_info)) + return await self.async_step_discovery(cast(dict, discovery_info)) async_step_ssdp = async_step_discovery async_step_mqtt = async_step_discovery From c9ec337bb2684210729a3df6cb2179bd1b843b93 Mon Sep 17 00:00:00 2001 From: epenet Date: Mon, 15 Nov 2021 16:27:38 +0000 Subject: [PATCH 22/22] Duplicate async_step_zeroconf code --- homeassistant/helpers/config_entry_flow.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/config_entry_flow.py b/homeassistant/helpers/config_entry_flow.py index 578d75eb8c04a5..1e87d0042d772e 100644 --- a/homeassistant/helpers/config_entry_flow.py +++ b/homeassistant/helpers/config_entry_flow.py @@ -2,7 +2,7 @@ from __future__ import annotations import logging -from typing import Any, Awaitable, Callable, Union, cast +from typing import Any, Awaitable, Callable, Union from homeassistant import config_entries from homeassistant.components import zeroconf @@ -86,7 +86,12 @@ async def async_step_zeroconf( self, discovery_info: zeroconf.ZeroconfServiceInfo ) -> FlowResult: """Handle a flow initialized by Zeroconf discovery.""" - return await self.async_step_discovery(cast(dict, discovery_info)) + if self._async_in_progress() or self._async_current_entries(): + return self.async_abort(reason="single_instance_allowed") + + await self.async_set_unique_id(self._domain) + + return await self.async_step_confirm() async_step_ssdp = async_step_discovery async_step_mqtt = async_step_discovery