diff --git a/homeassistant/components/xiaomi_aqara/config_flow.py b/homeassistant/components/xiaomi_aqara/config_flow.py index a89bb8447a3..6252e6849d0 100644 --- a/homeassistant/components/xiaomi_aqara/config_flow.py +++ b/homeassistant/components/xiaomi_aqara/config_flow.py @@ -2,7 +2,7 @@ import logging from socket import gaierror -from typing import TYPE_CHECKING, Any +from typing import Any import voluptuous as vol from xiaomi_gateway import MULTICAST_PORT, XiaomiGateway, XiaomiGatewayDiscovery @@ -50,13 +50,14 @@ class XiaomiAqaraFlowHandler(ConfigFlow, domain=DOMAIN): VERSION = 1 + selected_gateway: XiaomiGateway + gateways: dict[str, XiaomiGateway] + def __init__(self) -> None: """Initialize.""" self.host: str | None = None self.interface = DEFAULT_INTERFACE self.sid: str | None = None - self.gateways: dict[str, XiaomiGateway] | None = None - self.selected_gateway: XiaomiGateway | None = None @callback def async_show_form_step_user(self, errors): @@ -99,8 +100,6 @@ class XiaomiAqaraFlowHandler(ConfigFlow, domain=DOMAIN): None, ) - if TYPE_CHECKING: - assert self.selected_gateway if self.selected_gateway.connection_error: errors[CONF_HOST] = "invalid_host" if self.selected_gateway.mac_error: @@ -120,8 +119,6 @@ class XiaomiAqaraFlowHandler(ConfigFlow, domain=DOMAIN): self.gateways = xiaomi.gateways - if TYPE_CHECKING: - assert self.gateways is not None if len(self.gateways) == 1: self.selected_gateway = list(self.gateways.values())[0] self.sid = self.selected_gateway.sid @@ -132,9 +129,11 @@ class XiaomiAqaraFlowHandler(ConfigFlow, domain=DOMAIN): errors["base"] = "discovery_error" return self.async_show_form_step_user(errors) - async def async_step_select(self, user_input=None): + async def async_step_select( + self, user_input: dict[str, str] | None = None + ) -> ConfigFlowResult: """Handle multiple aqara gateways found.""" - errors = {} + errors: dict[str, str] = {} if user_input is not None: ip_adress = user_input["select_ip"] self.selected_gateway = self.gateways[ip_adress] @@ -192,7 +191,9 @@ class XiaomiAqaraFlowHandler(ConfigFlow, domain=DOMAIN): return await self.async_step_user() - async def async_step_settings(self, user_input=None): + async def async_step_settings( + self, user_input: dict[str, str] | None = None + ) -> ConfigFlowResult: """Specify settings and connect aqara gateway.""" errors = {} if user_input is not None: