From 9a09c1b027c6905e0ea6a089eea19bd85eb9542d Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 19 Oct 2024 09:56:36 +0200 Subject: [PATCH] Use new reauth_helpers in nice_go (#128702) --- .../components/nice_go/config_flow.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/nice_go/config_flow.py b/homeassistant/components/nice_go/config_flow.py index 94594bbd11f..da3940117e9 100644 --- a/homeassistant/components/nice_go/config_flow.py +++ b/homeassistant/components/nice_go/config_flow.py @@ -5,7 +5,7 @@ from __future__ import annotations from collections.abc import Mapping from datetime import datetime import logging -from typing import TYPE_CHECKING, Any +from typing import Any from nice_go import AuthFailedError, NiceGOApi 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.helpers.aiohttp_client import async_get_clientsession -from . import NiceGOConfigEntry from .const import CONF_REFRESH_TOKEN, CONF_REFRESH_TOKEN_CREATION_TIME, DOMAIN _LOGGER = logging.getLogger(__name__) @@ -31,7 +30,6 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for Nice G.O.""" VERSION = 1 - reauth_entry: NiceGOConfigEntry | None async def async_step_user( self, user_input: dict[str, Any] | None = None @@ -74,10 +72,6 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle re-authentication.""" - 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( @@ -86,9 +80,7 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN): """Confirm re-authentication.""" errors = {} - if TYPE_CHECKING: - assert self.reauth_entry is not None - + reauth_entry = self._get_reauth_entry() if user_input is not None: hub = NiceGOApi() @@ -105,7 +97,7 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN): errors["base"] = "unknown" else: return self.async_update_reload_and_abort( - self.reauth_entry, + reauth_entry, data={ **user_input, CONF_REFRESH_TOKEN: refresh_token, @@ -118,8 +110,8 @@ class NiceGOConfigFlow(ConfigFlow, domain=DOMAIN): step_id="reauth_confirm", data_schema=self.add_suggested_values_to_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, )