From 7a9385d85714c222342b4c16719e7a6c3453dc6b Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Sat, 17 Apr 2021 11:42:31 +0100 Subject: [PATCH] Explicitly define all methods in ConfigFlow (#49341) --- homeassistant/components/bond/config_flow.py | 2 +- .../components/broadlink/config_flow.py | 6 +-- .../components/emonitor/config_flow.py | 8 ++-- .../components/huawei_lte/config_flow.py | 2 +- .../hunterdouglas_powerview/config_flow.py | 12 +++--- .../components/hyperion/config_flow.py | 2 +- homeassistant/components/myq/config_flow.py | 4 +- .../components/powerwall/config_flow.py | 6 +-- .../components/rachio/config_flow.py | 4 +- .../components/roomba/config_flow.py | 10 ++--- .../components/screenlogic/config_flow.py | 10 ++--- .../components/shelly/config_flow.py | 10 ++--- .../components/somfy_mylink/config_flow.py | 12 +++--- homeassistant/components/tado/config_flow.py | 4 +- homeassistant/components/wled/config_flow.py | 12 +++--- .../components/zwave_js/config_flow.py | 2 +- homeassistant/config_entries.py | 41 ++++++++++++++++--- 17 files changed, 88 insertions(+), 59 deletions(-) diff --git a/homeassistant/components/bond/config_flow.py b/homeassistant/components/bond/config_flow.py index d4bf0275ad9e..6829cfd4cc6b 100644 --- a/homeassistant/components/bond/config_flow.py +++ b/homeassistant/components/bond/config_flow.py @@ -92,7 +92,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): _, hub_name = await _validate_input(self.hass, self._discovered) self._discovered[CONF_NAME] = hub_name - async def async_step_zeroconf( # type: ignore[override] + async def async_step_zeroconf( self, discovery_info: DiscoveryInfoType ) -> FlowResultDict: """Handle a flow initialized by zeroconf discovery.""" diff --git a/homeassistant/components/broadlink/config_flow.py b/homeassistant/components/broadlink/config_flow.py index 158f3a271131..766c2c609403 100644 --- a/homeassistant/components/broadlink/config_flow.py +++ b/homeassistant/components/broadlink/config_flow.py @@ -56,10 +56,10 @@ class BroadlinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): "host": device.host[0], } - async def async_step_dhcp(self, dhcp_discovery): + async def async_step_dhcp(self, discovery_info): """Handle dhcp discovery.""" - host = dhcp_discovery[IP_ADDRESS] - unique_id = dhcp_discovery[MAC_ADDRESS].lower().replace(":", "") + host = discovery_info[IP_ADDRESS] + unique_id = discovery_info[MAC_ADDRESS].lower().replace(":", "") await self.async_set_unique_id(unique_id) self._abort_if_unique_id_configured(updates={CONF_HOST: host}) try: diff --git a/homeassistant/components/emonitor/config_flow.py b/homeassistant/components/emonitor/config_flow.py index bd5650d28cd1..70fa46e4ee7e 100644 --- a/homeassistant/components/emonitor/config_flow.py +++ b/homeassistant/components/emonitor/config_flow.py @@ -63,12 +63,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): errors=errors, ) - async def async_step_dhcp(self, dhcp_discovery): + async def async_step_dhcp(self, discovery_info): """Handle dhcp discovery.""" - self.discovered_ip = dhcp_discovery[IP_ADDRESS] - await self.async_set_unique_id(format_mac(dhcp_discovery[MAC_ADDRESS])) + self.discovered_ip = discovery_info[IP_ADDRESS] + await self.async_set_unique_id(format_mac(discovery_info[MAC_ADDRESS])) self._abort_if_unique_id_configured(updates={CONF_HOST: self.discovered_ip}) - name = name_short_mac(short_mac(dhcp_discovery[MAC_ADDRESS])) + name = name_short_mac(short_mac(discovery_info[MAC_ADDRESS])) self.context["title_placeholders"] = {"name": name} try: self.discovered_info = await fetch_mac_and_title( diff --git a/homeassistant/components/huawei_lte/config_flow.py b/homeassistant/components/huawei_lte/config_flow.py index 5f1cdf932528..cfd197e15150 100644 --- a/homeassistant/components/huawei_lte/config_flow.py +++ b/homeassistant/components/huawei_lte/config_flow.py @@ -213,7 +213,7 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): return self.async_create_entry(title=title, data=user_input) - async def async_step_ssdp( # type: ignore[override] + async def async_step_ssdp( self, discovery_info: DiscoveryInfoType ) -> FlowResultDict: """Handle SSDP initiated config flow.""" diff --git a/homeassistant/components/hunterdouglas_powerview/config_flow.py b/homeassistant/components/hunterdouglas_powerview/config_flow.py index 928c4b4819f4..8332e1e856f8 100644 --- a/homeassistant/components/hunterdouglas_powerview/config_flow.py +++ b/homeassistant/components/hunterdouglas_powerview/config_flow.py @@ -78,30 +78,30 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="user", data_schema=DATA_SCHEMA, errors=errors ) - async def async_step_homekit(self, homekit_info): + async def async_step_homekit(self, discovery_info): """Handle HomeKit discovery.""" # If we already have the host configured do # not open connections to it if we can avoid it. - if self._host_already_configured(homekit_info[CONF_HOST]): + if self._host_already_configured(discovery_info[CONF_HOST]): return self.async_abort(reason="already_configured") try: - info = await validate_input(self.hass, homekit_info) + info = await validate_input(self.hass, discovery_info) except CannotConnect: return self.async_abort(reason="cannot_connect") except Exception: # pylint: disable=broad-except return self.async_abort(reason="unknown") await self.async_set_unique_id(info["unique_id"], raise_on_progress=False) - self._abort_if_unique_id_configured({CONF_HOST: homekit_info["host"]}) + self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]}) - name = homekit_info["name"] + name = discovery_info["name"] if name.endswith(HAP_SUFFIX): name = name[: -len(HAP_SUFFIX)] self.powerview_config = { - CONF_HOST: homekit_info["host"], + CONF_HOST: discovery_info["host"], CONF_NAME: name, } return await self.async_step_link() diff --git a/homeassistant/components/hyperion/config_flow.py b/homeassistant/components/hyperion/config_flow.py index 1a087460151f..229859111ac6 100644 --- a/homeassistant/components/hyperion/config_flow.py +++ b/homeassistant/components/hyperion/config_flow.py @@ -154,7 +154,7 @@ class HyperionConfigFlow(ConfigFlow, domain=DOMAIN): return self.async_abort(reason="cannot_connect") return await self._advance_to_auth_step_if_necessary(hyperion_client) - async def async_step_ssdp(self, discovery_info: dict[str, Any]) -> FlowResultDict: # type: ignore[override] + async def async_step_ssdp(self, discovery_info: dict[str, Any]) -> FlowResultDict: """Handle a flow initiated by SSDP.""" # Sample data provided by SSDP: { # 'ssdp_location': 'http://192.168.0.1:8090/description.xml', diff --git a/homeassistant/components/myq/config_flow.py b/homeassistant/components/myq/config_flow.py index 17c98195a4ed..b472184616f7 100644 --- a/homeassistant/components/myq/config_flow.py +++ b/homeassistant/components/myq/config_flow.py @@ -65,7 +65,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="user", data_schema=DATA_SCHEMA, errors=errors ) - async def async_step_homekit(self, homekit_info): + async def async_step_homekit(self, discovery_info): """Handle HomeKit discovery.""" if self._async_current_entries(): # We can see myq on the network to tell them to configure @@ -76,7 +76,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # add a new one via "+" return self.async_abort(reason="already_configured") properties = { - key.lower(): value for (key, value) in homekit_info["properties"].items() + key.lower(): value for (key, value) in discovery_info["properties"].items() } await self.async_set_unique_id(properties["id"]) return await self.async_step_user() diff --git a/homeassistant/components/powerwall/config_flow.py b/homeassistant/components/powerwall/config_flow.py index 579c916a15ad..640993af74d9 100644 --- a/homeassistant/components/powerwall/config_flow.py +++ b/homeassistant/components/powerwall/config_flow.py @@ -59,12 +59,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Initialize the powerwall flow.""" self.ip_address = None - async def async_step_dhcp(self, dhcp_discovery): + async def async_step_dhcp(self, discovery_info): """Handle dhcp discovery.""" - if self._async_ip_address_already_configured(dhcp_discovery[IP_ADDRESS]): + if self._async_ip_address_already_configured(discovery_info[IP_ADDRESS]): return self.async_abort(reason="already_configured") - self.ip_address = dhcp_discovery[IP_ADDRESS] + self.ip_address = discovery_info[IP_ADDRESS] self.context["title_placeholders"] = {CONF_IP_ADDRESS: self.ip_address} return await self.async_step_user() diff --git a/homeassistant/components/rachio/config_flow.py b/homeassistant/components/rachio/config_flow.py index 5719dd810660..306b05d09a67 100644 --- a/homeassistant/components/rachio/config_flow.py +++ b/homeassistant/components/rachio/config_flow.py @@ -78,7 +78,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="user", data_schema=DATA_SCHEMA, errors=errors ) - async def async_step_homekit(self, homekit_info): + async def async_step_homekit(self, discovery_info): """Handle HomeKit discovery.""" if self._async_current_entries(): # We can see rachio on the network to tell them to configure @@ -89,7 +89,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # add a new one via "+" return self.async_abort(reason="already_configured") properties = { - key.lower(): value for (key, value) in homekit_info["properties"].items() + key.lower(): value for (key, value) in discovery_info["properties"].items() } await self.async_set_unique_id(properties["id"]) return await self.async_step_user() diff --git a/homeassistant/components/roomba/config_flow.py b/homeassistant/components/roomba/config_flow.py index 45c2d8b9a1bd..5603d9d9d7e0 100644 --- a/homeassistant/components/roomba/config_flow.py +++ b/homeassistant/components/roomba/config_flow.py @@ -78,16 +78,16 @@ class RoombaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Get the options flow for this handler.""" return OptionsFlowHandler(config_entry) - async def async_step_dhcp(self, dhcp_discovery): + async def async_step_dhcp(self, discovery_info): """Handle dhcp discovery.""" - if self._async_host_already_configured(dhcp_discovery[IP_ADDRESS]): + if self._async_host_already_configured(discovery_info[IP_ADDRESS]): return self.async_abort(reason="already_configured") - if not dhcp_discovery[HOSTNAME].startswith(("irobot-", "roomba-")): + if not discovery_info[HOSTNAME].startswith(("irobot-", "roomba-")): return self.async_abort(reason="not_irobot_device") - self.host = dhcp_discovery[IP_ADDRESS] - self.blid = _async_blid_from_hostname(dhcp_discovery[HOSTNAME]) + self.host = discovery_info[IP_ADDRESS] + self.blid = _async_blid_from_hostname(discovery_info[HOSTNAME]) await self.async_set_unique_id(self.blid) self._abort_if_unique_id_configured(updates={CONF_HOST: self.host}) diff --git a/homeassistant/components/screenlogic/config_flow.py b/homeassistant/components/screenlogic/config_flow.py index 4f3887221171..fb33bd7e2276 100644 --- a/homeassistant/components/screenlogic/config_flow.py +++ b/homeassistant/components/screenlogic/config_flow.py @@ -89,15 +89,15 @@ class ScreenlogicConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self.discovered_gateways = await async_discover_gateways_by_unique_id(self.hass) return await self.async_step_gateway_select() - async def async_step_dhcp(self, dhcp_discovery): + async def async_step_dhcp(self, discovery_info): """Handle dhcp discovery.""" - mac = _extract_mac_from_name(dhcp_discovery[HOSTNAME]) + mac = _extract_mac_from_name(discovery_info[HOSTNAME]) await self.async_set_unique_id(mac) self._abort_if_unique_id_configured( - updates={CONF_IP_ADDRESS: dhcp_discovery[IP_ADDRESS]} + updates={CONF_IP_ADDRESS: discovery_info[IP_ADDRESS]} ) - self.discovered_ip = dhcp_discovery[IP_ADDRESS] - self.context["title_placeholders"] = {"name": dhcp_discovery[HOSTNAME]} + self.discovered_ip = discovery_info[IP_ADDRESS] + self.context["title_placeholders"] = {"name": discovery_info[HOSTNAME]} return await self.async_step_gateway_entry() async def async_step_gateway_select(self, user_input=None): diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index 73c231086eff..a2eaa21bf1d0 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -146,21 +146,21 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="credentials", data_schema=schema, errors=errors ) - async def async_step_zeroconf(self, zeroconf_info): + async def async_step_zeroconf(self, discovery_info): """Handle zeroconf discovery.""" try: - self.info = info = await self._async_get_info(zeroconf_info["host"]) + self.info = info = await self._async_get_info(discovery_info["host"]) except HTTP_CONNECT_ERRORS: return self.async_abort(reason="cannot_connect") except aioshelly.FirmwareUnsupported: return self.async_abort(reason="unsupported_firmware") await self.async_set_unique_id(info["mac"]) - self._abort_if_unique_id_configured({CONF_HOST: zeroconf_info["host"]}) - self.host = zeroconf_info["host"] + self._abort_if_unique_id_configured({CONF_HOST: discovery_info["host"]}) + self.host = discovery_info["host"] self.context["title_placeholders"] = { - "name": zeroconf_info.get("name", "").split(".")[0] + "name": discovery_info.get("name", "").split(".")[0] } if info["auth"]: diff --git a/homeassistant/components/somfy_mylink/config_flow.py b/homeassistant/components/somfy_mylink/config_flow.py index d1a1e19609ad..739251e041fe 100644 --- a/homeassistant/components/somfy_mylink/config_flow.py +++ b/homeassistant/components/somfy_mylink/config_flow.py @@ -59,19 +59,19 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self.mac = None self.ip_address = None - async def async_step_dhcp(self, dhcp_discovery): + async def async_step_dhcp(self, discovery_info): """Handle dhcp discovery.""" - if self._host_already_configured(dhcp_discovery[IP_ADDRESS]): + if self._host_already_configured(discovery_info[IP_ADDRESS]): return self.async_abort(reason="already_configured") - formatted_mac = format_mac(dhcp_discovery[MAC_ADDRESS]) + formatted_mac = format_mac(discovery_info[MAC_ADDRESS]) await self.async_set_unique_id(format_mac(formatted_mac)) self._abort_if_unique_id_configured( - updates={CONF_HOST: dhcp_discovery[IP_ADDRESS]} + updates={CONF_HOST: discovery_info[IP_ADDRESS]} ) - self.host = dhcp_discovery[HOSTNAME] + self.host = discovery_info[HOSTNAME] self.mac = formatted_mac - self.ip_address = dhcp_discovery[IP_ADDRESS] + self.ip_address = discovery_info[IP_ADDRESS] self.context["title_placeholders"] = {"ip": self.ip_address, "mac": self.mac} return await self.async_step_user() diff --git a/homeassistant/components/tado/config_flow.py b/homeassistant/components/tado/config_flow.py index 5f97212abf34..77824affecaa 100644 --- a/homeassistant/components/tado/config_flow.py +++ b/homeassistant/components/tado/config_flow.py @@ -81,7 +81,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="user", data_schema=DATA_SCHEMA, errors=errors ) - async def async_step_homekit(self, homekit_info): + async def async_step_homekit(self, discovery_info): """Handle HomeKit discovery.""" if self._async_current_entries(): # We can see tado on the network to tell them to configure @@ -92,7 +92,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # add a new one via "+" return self.async_abort(reason="already_configured") properties = { - key.lower(): value for (key, value) in homekit_info["properties"].items() + key.lower(): value for (key, value) in discovery_info["properties"].items() } await self.async_set_unique_id(properties["id"]) return await self.async_step_user() diff --git a/homeassistant/components/wled/config_flow.py b/homeassistant/components/wled/config_flow.py index a85a74fa94bc..9b57109d18fa 100644 --- a/homeassistant/components/wled/config_flow.py +++ b/homeassistant/components/wled/config_flow.py @@ -31,27 +31,27 @@ class WLEDFlowHandler(ConfigFlow, domain=DOMAIN): return await self._handle_config_flow(user_input) async def async_step_zeroconf( - self, user_input: ConfigType | None = None + self, discovery_info: ConfigType | None = None ) -> dict[str, Any]: """Handle zeroconf discovery.""" - if user_input is None: + if discovery_info is None: return self.async_abort(reason="cannot_connect") # Hostname is format: wled-livingroom.local. - host = user_input["hostname"].rstrip(".") + host = discovery_info["hostname"].rstrip(".") name, _ = host.rsplit(".") self.context.update( { - CONF_HOST: user_input["host"], + CONF_HOST: discovery_info["host"], CONF_NAME: name, - CONF_MAC: user_input["properties"].get(CONF_MAC), + CONF_MAC: discovery_info["properties"].get(CONF_MAC), "title_placeholders": {"name": name}, } ) # Prepare configuration flow - return await self._handle_config_flow(user_input, True) + return await self._handle_config_flow(discovery_info, True) async def async_step_zeroconf_confirm( self, user_input: ConfigType = None diff --git a/homeassistant/components/zwave_js/config_flow.py b/homeassistant/components/zwave_js/config_flow.py index a2429a25c1b1..b2bc5c0e0e03 100644 --- a/homeassistant/components/zwave_js/config_flow.py +++ b/homeassistant/components/zwave_js/config_flow.py @@ -134,7 +134,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="manual", data_schema=STEP_USER_DATA_SCHEMA, errors=errors ) - async def async_step_hassio(self, discovery_info: dict[str, Any]) -> FlowResultDict: # type: ignore[override] + async def async_step_hassio(self, discovery_info: dict[str, Any]) -> FlowResultDict: """Receive configuration from add-on discovery info. This flow is triggered by the Z-Wave JS add-on. diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index c69cd0c9d5b4..bf9a45d06f0c 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -1229,12 +1229,41 @@ class ConfigFlow(data_entry_flow.FlowHandler): reason=reason, description_placeholders=description_placeholders ) - async_step_hassio = async_step_discovery - async_step_homekit = async_step_discovery - async_step_mqtt = async_step_discovery - async_step_ssdp = async_step_discovery - async_step_zeroconf = async_step_discovery - async_step_dhcp = async_step_discovery + async def async_step_hassio( + self, discovery_info: DiscoveryInfoType + ) -> data_entry_flow.FlowResultDict: + """Handle a flow initialized by HASS IO discovery.""" + return await self.async_step_discovery(discovery_info) + + async def async_step_homekit( + self, discovery_info: DiscoveryInfoType + ) -> data_entry_flow.FlowResultDict: + """Handle a flow initialized by Homekit discovery.""" + return await self.async_step_discovery(discovery_info) + + async def async_step_mqtt( + self, discovery_info: DiscoveryInfoType + ) -> data_entry_flow.FlowResultDict: + """Handle a flow initialized by MQTT discovery.""" + return await self.async_step_discovery(discovery_info) + + async def async_step_ssdp( + self, discovery_info: DiscoveryInfoType + ) -> data_entry_flow.FlowResultDict: + """Handle a flow initialized by SSDP discovery.""" + return await self.async_step_discovery(discovery_info) + + async def async_step_zeroconf( + self, discovery_info: DiscoveryInfoType + ) -> data_entry_flow.FlowResultDict: + """Handle a flow initialized by Zeroconf discovery.""" + return await self.async_step_discovery(discovery_info) + + async def async_step_dhcp( + self, discovery_info: DiscoveryInfoType + ) -> data_entry_flow.FlowResultDict: + """Handle a flow initialized by DHCP discovery.""" + return await self.async_step_discovery(discovery_info) class OptionsFlowManager(data_entry_flow.FlowManager):