66
77import jwt
88
9- from homeassistant .config_entries import ConfigEntry , ConfigFlowResult
9+ from homeassistant .config_entries import SOURCE_REAUTH , ConfigFlowResult
1010from homeassistant .helpers import config_entry_oauth2_flow
1111
1212from .const import DOMAIN
@@ -19,7 +19,6 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=
1919
2020 VERSION = 1
2121 DOMAIN = DOMAIN
22- reauth_entry : ConfigEntry | None = None
2322
2423 @property
2524 def logger (self ) -> logging .Logger :
@@ -30,9 +29,6 @@ async def async_step_reauth(
3029 self , entry_data : Mapping [str , Any ]
3130 ) -> ConfigFlowResult :
3231 """Handle configuration by re-auth."""
33- self .reauth_entry = self .hass .config_entries .async_get_entry (
34- self .context ["entry_id" ]
35- )
3632 return await self .async_step_user ()
3733
3834 def _async_get_user_id_from_access_token (self , encoded : str ) -> str :
@@ -51,10 +47,11 @@ async def async_oauth_create_entry(self, data: dict) -> ConfigFlowResult:
5147 user_id = self ._async_get_user_id_from_access_token (
5248 data ["token" ]["access_token" ]
5349 )
54- if entry := self .reauth_entry :
55- if entry .unique_id != user_id :
56- return self .async_abort (reason = "reauth_invalid_user" )
57- return self .async_update_reload_and_abort (entry , data = data )
5850 await self .async_set_unique_id (user_id )
51+ if self .source == SOURCE_REAUTH :
52+ self ._abort_if_unique_id_mismatch (reason = "reauth_invalid_user" )
53+ return self .async_update_reload_and_abort (
54+ self ._get_reauth_entry (), data = data
55+ )
5956 self ._abort_if_unique_id_configured ()
6057 return await super ().async_oauth_create_entry (data )
0 commit comments