Skip to content

Commit

Permalink
Use reauth helpers in google_tasks (home-assistant#128586)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 18, 2024
1 parent 84d4a1c commit c1c0a28
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions homeassistant/components/google_tasks/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from googleapiclient.errors import HttpError
from googleapiclient.http import HttpRequest

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 import config_entry_oauth2_flow

Expand All @@ -23,8 +23,6 @@ class OAuth2FlowHandler(

DOMAIN = DOMAIN

reauth_entry: ConfigEntry | None = None

@property
def logger(self) -> logging.Logger:
"""Return logger."""
Expand Down Expand Up @@ -70,25 +68,24 @@ async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResu
self.logger.exception("Unknown error occurred")
return self.async_abort(reason="unknown")
user_id = user_resource_info["id"]
if not self.reauth_entry:
await self.async_set_unique_id(user_id)
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=user_resource_info["name"], data=data)

if self.reauth_entry.unique_id == user_id or not self.reauth_entry.unique_id:
return self.async_update_reload_and_abort(
self.reauth_entry, unique_id=user_id, data=data
)
reauth_entry = self._get_reauth_entry()
if reauth_entry.unique_id:
self._abort_if_unique_id_mismatch(reason="wrong_account")

return self.async_abort(reason="wrong_account")
return self.async_update_reload_and_abort(
reauth_entry, unique_id=user_id, data=data
)

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(
Expand Down

0 comments on commit c1c0a28

Please sign in to comment.