mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Use new reauth helpers in weheat (#128824)
This commit is contained in:
parent
c8556f69e7
commit
4fc872a4cb
@ -6,7 +6,7 @@ from typing import Any
|
||||
|
||||
from weheat.abstractions.user import get_user_id_from_token
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlowResult
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN
|
||||
from homeassistant.helpers.config_entry_oauth2_flow import AbstractOAuth2FlowHandler
|
||||
|
||||
@ -18,8 +18,6 @@ class OAuth2FlowHandler(AbstractOAuth2FlowHandler, domain=DOMAIN):
|
||||
|
||||
DOMAIN = DOMAIN
|
||||
|
||||
reauth_entry: ConfigEntry | None = None
|
||||
|
||||
@property
|
||||
def logger(self) -> logging.Logger:
|
||||
"""Return logger."""
|
||||
@ -38,28 +36,21 @@ class OAuth2FlowHandler(AbstractOAuth2FlowHandler, domain=DOMAIN):
|
||||
user_id = await get_user_id_from_token(
|
||||
API_URL, data[CONF_TOKEN][CONF_ACCESS_TOKEN]
|
||||
)
|
||||
if not self.reauth_entry:
|
||||
await self.async_set_unique_id(user_id)
|
||||
if self.source != SOURCE_REAUTH:
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return self.async_create_entry(title=ENTRY_TITLE, data=data)
|
||||
|
||||
if self.reauth_entry.unique_id == user_id:
|
||||
self._abort_if_unique_id_mismatch(reason="wrong_account")
|
||||
return self.async_update_reload_and_abort(
|
||||
self.reauth_entry,
|
||||
unique_id=user_id,
|
||||
data={**self.reauth_entry.data, **data},
|
||||
self._get_reauth_entry(), data_updates=data
|
||||
)
|
||||
|
||||
return self.async_abort(reason="wrong_account")
|
||||
|
||||
async def async_step_reauth(
|
||||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Perform reauth upon an API authentication error."""
|
||||
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
return await self.async_step_reauth_confirm()
|
||||
|
||||
async def async_step_reauth_confirm(
|
||||
|
Loading…
x
Reference in New Issue
Block a user