44
55from datetime import timedelta
66import logging
7+ from typing import Self
78
89from requests .exceptions import RequestException
910import voluptuous as vol
1011
11- from homeassistant import config_entries
12- from homeassistant .config_entries import ConfigEntry
12+ from homeassistant .config_entries import ConfigFlow , ConfigFlowResult , OptionsFlow
1313from homeassistant .core import callback
14- from homeassistant .data_entry_flow import FlowResult
1514from homeassistant .helpers .aiohttp_client import async_create_clientsession
1615
1716from .api import GlocaltokensApiClient
2827 UPDATE_INTERVAL ,
2928)
3029from .exceptions import InvalidMasterToken
31- from .types import ConfigFlowDict , OptionsFlowDict
30+ from .types import ConfigFlowDict , GoogleHomeConfigEntry , OptionsFlowDict
3231
3332_LOGGER : logging .Logger = logging .getLogger (__package__ )
3433
3534
36- class GoogleHomeFlowHandler (config_entries . ConfigFlow , domain = DOMAIN ):
35+ class GoogleHomeFlowHandler (ConfigFlow , domain = DOMAIN ):
3736 """Config flow for GoogleHome."""
3837
3938 VERSION = 1
4039
4140 def __init__ (self ) -> None :
4241 """Initialize."""
42+ self .username : str | None = None
4343 self ._errors : dict [str , str ] = {}
4444
45+ def is_matching (self , other_flow : Self ) -> bool :
46+ """Return True if other_flow is matching this flow."""
47+ return other_flow .username == self .username
48+
4549 async def async_step_user (
4650 self , user_input : ConfigFlowDict | None = None # type: ignore[override]
47- ) -> FlowResult :
51+ ) -> ConfigFlowResult :
4852 """Handle a flow initialized by the user."""
4953 self ._errors = {}
5054
@@ -55,6 +59,7 @@ async def async_step_user(
5559 if user_input is not None :
5660 session = async_create_clientsession (self .hass )
5761 username = user_input .get (CONF_USERNAME , "" )
62+ self .username = username
5863 password = user_input .get (CONF_PASSWORD , "" )
5964 master_token = user_input .get (CONF_MASTER_TOKEN , "" )
6065
@@ -104,11 +109,11 @@ async def async_step_user(
104109 @staticmethod
105110 @callback
106111 def async_get_options_flow (
107- config_entry : ConfigEntry ,
112+ config_entry : GoogleHomeConfigEntry ,
108113 ) -> GoogleHomeOptionsFlowHandler :
109114 return GoogleHomeOptionsFlowHandler (config_entry )
110115
111- async def _show_config_form (self ) -> FlowResult :
116+ async def _show_config_form (self ) -> ConfigFlowResult :
112117 """Show the configuration form to edit login information."""
113118 return self .async_show_form (
114119 step_id = "user" ,
@@ -143,18 +148,18 @@ async def _get_access_token(client: GlocaltokensApiClient) -> str:
143148 return access_token
144149
145150
146- class GoogleHomeOptionsFlowHandler (config_entries . OptionsFlow ):
151+ class GoogleHomeOptionsFlowHandler (OptionsFlow ):
147152 """Config flow options handler for GoogleHome."""
148153
149- def __init__ (self , config_entry : ConfigEntry ):
154+ def __init__ (self , config_entry : GoogleHomeConfigEntry ):
150155 """Initialize options flow."""
151156 self .config_entry = config_entry
152157 # Cast from MappingProxy to dict to allow update.
153158 self .options = dict (config_entry .options )
154159
155160 async def async_step_init (
156161 self , user_input : OptionsFlowDict | None = None
157- ) -> FlowResult :
162+ ) -> ConfigFlowResult :
158163 """Manage the options."""
159164 if user_input is not None :
160165 self .options .update (user_input )
0 commit comments