mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Use reauth helpers in fitbit (#128568)
This commit is contained in:
parent
f37c0e0548
commit
f08d2716ae
@ -4,7 +4,7 @@ from collections.abc import Mapping
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_TOKEN
|
from homeassistant.const import CONF_TOKEN
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
|
||||||
@ -22,8 +22,6 @@ class OAuth2FlowHandler(
|
|||||||
|
|
||||||
DOMAIN = DOMAIN
|
DOMAIN = DOMAIN
|
||||||
|
|
||||||
reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def logger(self) -> logging.Logger:
|
def logger(self) -> logging.Logger:
|
||||||
"""Return logger."""
|
"""Return logger."""
|
||||||
@ -34,16 +32,13 @@ class OAuth2FlowHandler(
|
|||||||
"""Extra data that needs to be appended to the authorize url."""
|
"""Extra data that needs to be appended to the authorize url."""
|
||||||
return {
|
return {
|
||||||
"scope": " ".join(OAUTH_SCOPES),
|
"scope": " ".join(OAUTH_SCOPES),
|
||||||
"prompt": "consent" if not self.reauth_entry else "none",
|
"prompt": "consent" if self.source != SOURCE_REAUTH else "none",
|
||||||
}
|
}
|
||||||
|
|
||||||
async def async_step_reauth(
|
async def async_step_reauth(
|
||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""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()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
@ -82,14 +77,13 @@ class OAuth2FlowHandler(
|
|||||||
_LOGGER.error("Failed to fetch user profile for Fitbit API: %s", err)
|
_LOGGER.error("Failed to fetch user profile for Fitbit API: %s", err)
|
||||||
return self.async_abort(reason="cannot_connect")
|
return self.async_abort(reason="cannot_connect")
|
||||||
|
|
||||||
if self.reauth_entry:
|
|
||||||
if self.reauth_entry.unique_id != profile.encoded_id:
|
|
||||||
return self.async_abort(reason="wrong_account")
|
|
||||||
self.hass.config_entries.async_update_entry(self.reauth_entry, data=data)
|
|
||||||
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
await self.async_set_unique_id(profile.encoded_id)
|
await self.async_set_unique_id(profile.encoded_id)
|
||||||
|
if self.source == SOURCE_REAUTH:
|
||||||
|
self._abort_if_unique_id_mismatch(reason="wrong_account")
|
||||||
|
return self.async_update_reload_and_abort(
|
||||||
|
self._get_reauth_entry(), data=data
|
||||||
|
)
|
||||||
|
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(title=profile.display_name, data=data)
|
return self.async_create_entry(title=profile.display_name, data=data)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user