Use new reauth helpers in yale (#128828)

This commit is contained in:
epenet 2024-10-20 10:01:53 +02:00 committed by GitHub
parent d9c61a37bb
commit 5228aa5e5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,7 @@ from typing import Any
import jwt
from homeassistant.config_entries import ConfigEntry, ConfigFlowResult
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
from homeassistant.helpers import config_entry_oauth2_flow
from .const import DOMAIN
@ -19,7 +19,6 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=
VERSION = 1
DOMAIN = DOMAIN
reauth_entry: ConfigEntry | None = None
@property
def logger(self) -> logging.Logger:
@ -30,9 +29,6 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle configuration by re-auth."""
self.reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
return await self.async_step_user()
def _async_get_user_id_from_access_token(self, encoded: str) -> str:
@ -51,10 +47,11 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=
user_id = self._async_get_user_id_from_access_token(
data["token"]["access_token"]
)
if entry := self.reauth_entry:
if entry.unique_id != user_id:
return self.async_abort(reason="reauth_invalid_user")
return self.async_update_reload_and_abort(entry, data=data)
await self.async_set_unique_id(user_id)
if self.source == SOURCE_REAUTH:
self._abort_if_unique_id_mismatch(reason="reauth_invalid_user")
return self.async_update_reload_and_abort(
self._get_reauth_entry(), data=data
)
self._abort_if_unique_id_configured()
return await super().async_oauth_create_entry(data)