mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Use new reauth_helpers in microbees (#128692)
This commit is contained in:
parent
ad3effa7d1
commit
3ac05f1fa9
@ -6,8 +6,7 @@ from typing import Any
|
|||||||
|
|
||||||
from microBeesPy import MicroBees, MicroBeesException
|
from microBeesPy import MicroBees, MicroBeesException
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
|
||||||
from homeassistant.config_entries import ConfigFlowResult
|
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN
|
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN
|
||||||
from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow
|
from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow
|
||||||
|
|
||||||
@ -20,7 +19,6 @@ class OAuth2FlowHandler(
|
|||||||
"""Handle a config flow for microBees."""
|
"""Handle a config flow for microBees."""
|
||||||
|
|
||||||
DOMAIN = DOMAIN
|
DOMAIN = DOMAIN
|
||||||
reauth_entry: config_entries.ConfigEntry | None = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def logger(self) -> logging.Logger:
|
def logger(self) -> logging.Logger:
|
||||||
@ -49,26 +47,21 @@ class OAuth2FlowHandler(
|
|||||||
self.logger.exception("Unexpected error")
|
self.logger.exception("Unexpected error")
|
||||||
return self.async_abort(reason="unknown")
|
return self.async_abort(reason="unknown")
|
||||||
|
|
||||||
if not self.reauth_entry:
|
await self.async_set_unique_id(current_user.id)
|
||||||
await self.async_set_unique_id(current_user.id)
|
if self.source != SOURCE_REAUTH:
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=current_user.username,
|
title=current_user.username,
|
||||||
data=data,
|
data=data,
|
||||||
)
|
)
|
||||||
if self.reauth_entry.unique_id == current_user.id:
|
|
||||||
self.hass.config_entries.async_update_entry(self.reauth_entry, data=data)
|
self._abort_if_unique_id_mismatch(reason="wrong_account")
|
||||||
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
return self.async_update_reload_and_abort(self._get_reauth_entry(), data=data)
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
return self.async_abort(reason="wrong_account")
|
|
||||||
|
|
||||||
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(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user