diff --git a/homeassistant/components/radarr/config_flow.py b/homeassistant/components/radarr/config_flow.py index ab32a5d7352..d02038d7131 100644 --- a/homeassistant/components/radarr/config_flow.py +++ b/homeassistant/components/radarr/config_flow.py @@ -12,12 +12,11 @@ from aiopyarr.radarr_client import RadarrClient import voluptuous as vol from yarl import URL -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 RadarrConfigEntry from .const import DEFAULT_NAME, DEFAULT_URL, DOMAIN @@ -25,14 +24,11 @@ class RadarrConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for Radarr.""" VERSION = 1 - entry: RadarrConfigEntry | 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( @@ -51,10 +47,7 @@ class RadarrConfigFlow(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: # aiopyarr defaults to the service port if one isn't given # this is counter to standard practice where http = 80 # and https = 443. @@ -75,20 +68,21 @@ class RadarrConfigFlow(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(