Use reauth helpers in google_assistant_sdk (#128582)
parent
cd4a13ca55
commit
420070a1ee
homeassistant/components/google_assistant_sdk
|
@ -8,7 +8,12 @@ from typing import Any
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlowResult, OptionsFlow
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_REAUTH,
|
||||||
|
ConfigEntry,
|
||||||
|
ConfigFlowResult,
|
||||||
|
OptionsFlow,
|
||||||
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
|
||||||
|
@ -25,8 +30,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."""
|
||||||
|
@ -46,9 +49,6 @@ class OAuth2FlowHandler(
|
||||||
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(
|
||||||
|
@ -61,10 +61,10 @@ class OAuth2FlowHandler(
|
||||||
|
|
||||||
async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResult:
|
async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResult:
|
||||||
"""Create an entry for the flow, or update existing entry."""
|
"""Create an entry for the flow, or update existing entry."""
|
||||||
if self.reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
self.hass.config_entries.async_update_entry(self.reauth_entry, data=data)
|
return self.async_update_reload_and_abort(
|
||||||
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
self._get_reauth_entry(), data=data
|
||||||
return self.async_abort(reason="reauth_successful")
|
)
|
||||||
|
|
||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
# Config entry already exists, only one allowed.
|
# Config entry already exists, only one allowed.
|
||||||
|
|
Loading…
Reference in New Issue