Use reauth helpers in lidarr (#128657)

This commit is contained in:
epenet 2024-10-18 17:22:14 +02:00 committed by GitHub
parent 4d41f82794
commit 099a3f4f90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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(