Use new reauth_helpers in nice_go (#128702)

This commit is contained in:
epenet 2024-10-19 09:56:36 +02:00 committed by GitHub
parent a94968b6bb
commit 9a09c1b027
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,7 @@ from __future__ import annotations
from collections.abc import Mapping from collections.abc import Mapping
from datetime import datetime from datetime import datetime
import logging import logging
from typing import TYPE_CHECKING, Any from typing import Any
from nice_go import AuthFailedError, NiceGOApi from nice_go import AuthFailedError, NiceGOApi
import voluptuous as vol import voluptuous as vol
@ -14,7 +14,6 @@ from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_EMAIL, CONF_NAME, CONF_PASSWORD from homeassistant.const import CONF_EMAIL, CONF_NAME, CONF_PASSWORD
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from . import NiceGOConfigEntry
from .const import CONF_REFRESH_TOKEN, CONF_REFRESH_TOKEN_CREATION_TIME, DOMAIN from .const import CONF_REFRESH_TOKEN, CONF_REFRESH_TOKEN_CREATION_TIME, DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -31,7 +30,6 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Nice G.O.""" """Handle a config flow for Nice G.O."""
VERSION = 1 VERSION = 1
reauth_entry: NiceGOConfigEntry | None
async def async_step_user( async def async_step_user(
self, user_input: dict[str, Any] | None = None self, user_input: dict[str, Any] | None = None
@ -74,10 +72,6 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any] self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Handle re-authentication.""" """Handle re-authentication."""
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(
@ -86,9 +80,7 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN):
"""Confirm re-authentication.""" """Confirm re-authentication."""
errors = {} errors = {}
if TYPE_CHECKING: reauth_entry = self._get_reauth_entry()
assert self.reauth_entry is not None
if user_input is not None: if user_input is not None:
hub = NiceGOApi() hub = NiceGOApi()
@ -105,7 +97,7 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN):
errors["base"] = "unknown" errors["base"] = "unknown"
else: else:
return self.async_update_reload_and_abort( return self.async_update_reload_and_abort(
self.reauth_entry, reauth_entry,
data={ data={
**user_input, **user_input,
CONF_REFRESH_TOKEN: refresh_token, CONF_REFRESH_TOKEN: refresh_token,
@ -118,8 +110,8 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN):
step_id="reauth_confirm", step_id="reauth_confirm",
data_schema=self.add_suggested_values_to_schema( data_schema=self.add_suggested_values_to_schema(
STEP_USER_DATA_SCHEMA, STEP_USER_DATA_SCHEMA,
user_input or {CONF_EMAIL: self.reauth_entry.data[CONF_EMAIL]}, user_input or {CONF_EMAIL: reauth_entry.data[CONF_EMAIL]},
), ),
description_placeholders={CONF_NAME: self.reauth_entry.title}, description_placeholders={CONF_NAME: reauth_entry.title},
errors=errors, errors=errors,
) )