mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Use reauth helpers in lidarr (#128657)
This commit is contained in:
parent
4d41f82794
commit
099a3f4f90
@ -10,12 +10,11 @@ from aiopyarr import exceptions
|
|||||||
from aiopyarr.lidarr_client import LidarrClient
|
from aiopyarr.lidarr_client import LidarrClient
|
||||||
import voluptuous as vol
|
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.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from . import LidarrConfigEntry
|
|
||||||
from .const import DEFAULT_NAME, DOMAIN
|
from .const import DEFAULT_NAME, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
@ -24,16 +23,10 @@ class LidarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
"""Initialize the flow."""
|
|
||||||
self.entry: LidarrConfigEntry | None = None
|
|
||||||
|
|
||||||
async def async_step_reauth(
|
async def async_step_reauth(
|
||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle configuration by re-auth."""
|
"""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()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def 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."""
|
"""Handle a flow initiated by the user."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
if user_input is None:
|
if user_input is not None:
|
||||||
user_input = dict(self.entry.data) if self.entry else None
|
|
||||||
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
if result := await validate_input(self.hass, user_input):
|
if result := await validate_input(self.hass, user_input):
|
||||||
user_input[CONF_API_KEY] = result[1]
|
user_input[CONF_API_KEY] = result[1]
|
||||||
@ -70,17 +60,18 @@ class LidarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
except exceptions.ArrException:
|
except exceptions.ArrException:
|
||||||
errors = {"base": "unknown"}
|
errors = {"base": "unknown"}
|
||||||
if not errors:
|
if not errors:
|
||||||
if self.entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self.entry, data=user_input
|
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)
|
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(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user