From 099a3f4f90faaa436b5f21ea87fccbe41b3908a7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:22:14 +0200 Subject: [PATCH] Use reauth helpers in lidarr (#128657) --- .../components/lidarr/config_flow.py | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/lidarr/config_flow.py b/homeassistant/components/lidarr/config_flow.py index bc7a40c976e..dfbfff2cdfd 100644 --- a/homeassistant/components/lidarr/config_flow.py +++ b/homeassistant/components/lidarr/config_flow.py @@ -10,12 +10,11 @@ from aiopyarr import exceptions from aiopyarr.lidarr_client import LidarrClient import voluptuous as vol -from homeassistant.config_entries import ConfigFlow, ConfigFlowResult +from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession -from . import LidarrConfigEntry from .const import DEFAULT_NAME, DOMAIN @@ -24,16 +23,10 @@ class LidarrConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 1 - def __init__(self) -> None: - """Initialize the flow.""" - self.entry: LidarrConfigEntry | None = None - async def async_step_reauth( self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle configuration by re-auth.""" - self.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( @@ -52,10 +45,7 @@ class LidarrConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a flow initiated by the user.""" errors = {} - if user_input is None: - user_input = dict(self.entry.data) if self.entry else None - - else: + if user_input is not None: try: if result := await validate_input(self.hass, user_input): user_input[CONF_API_KEY] = result[1] @@ -70,17 +60,18 @@ class LidarrConfigFlow(ConfigFlow, domain=DOMAIN): except exceptions.ArrException: errors = {"base": "unknown"} if not errors: - if self.entry: - self.hass.config_entries.async_update_entry( - self.entry, data=user_input + if self.source == SOURCE_REAUTH: + return self.async_update_reload_and_abort( + self._get_reauth_entry(), data=user_input ) - await self.hass.config_entries.async_reload(self.entry.entry_id) - - return self.async_abort(reason="reauth_successful") return self.async_create_entry(title=DEFAULT_NAME, data=user_input) - user_input = user_input or {} + if user_input is None: + user_input = {} + if self.source == SOURCE_REAUTH: + user_input = dict(self._get_reauth_entry().data) + return self.async_show_form( step_id="user", data_schema=vol.Schema(