From bcd77de3280808d31b6a75169b3d56bc345f60e6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 19 Oct 2024 10:12:22 +0200 Subject: [PATCH] Use new reauth helpers in pvoutput (#128720) --- .../components/pvoutput/config_flow.py | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/pvoutput/config_flow.py b/homeassistant/components/pvoutput/config_flow.py index 9d18952e7b4..ad2d759056f 100644 --- a/homeassistant/components/pvoutput/config_flow.py +++ b/homeassistant/components/pvoutput/config_flow.py @@ -8,7 +8,7 @@ from typing import Any from pvo import PVOutput, PVOutputAuthenticationError, PVOutputError import voluptuous as vol -from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult +from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_API_KEY from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -33,7 +33,6 @@ class PVOutputFlowHandler(ConfigFlow, domain=DOMAIN): VERSION = 1 imported_name: str | None = None - reauth_entry: ConfigEntry | None = None async def async_step_user( self, user_input: dict[str, Any] | None = None @@ -88,9 +87,6 @@ class PVOutputFlowHandler(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle initiation of re-authentication with PVOutput.""" - 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( @@ -99,29 +95,22 @@ class PVOutputFlowHandler(ConfigFlow, domain=DOMAIN): """Handle re-authentication with PVOutput.""" errors = {} - if user_input is not None and self.reauth_entry: + if user_input is not None: + reauth_entry = self._get_reauth_entry() try: await validate_input( self.hass, api_key=user_input[CONF_API_KEY], - system_id=self.reauth_entry.data[CONF_SYSTEM_ID], + system_id=reauth_entry.data[CONF_SYSTEM_ID], ) except PVOutputAuthenticationError: errors["base"] = "invalid_auth" except PVOutputError: errors["base"] = "cannot_connect" else: - self.hass.config_entries.async_update_entry( - self.reauth_entry, - data={ - **self.reauth_entry.data, - CONF_API_KEY: user_input[CONF_API_KEY], - }, + return self.async_update_reload_and_abort( + reauth_entry, data_updates=user_input ) - self.hass.async_create_task( - self.hass.config_entries.async_reload(self.reauth_entry.entry_id) - ) - return self.async_abort(reason="reauth_successful") return self.async_show_form( step_id="reauth_confirm",