mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17:07 +00:00
Use new reauth helpers in radarr (#128725)
This commit is contained in:
parent
004b323fd4
commit
391f278ee5
@ -12,12 +12,11 @@ from aiopyarr.radarr_client import RadarrClient
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from yarl import URL
|
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.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 RadarrConfigEntry
|
|
||||||
from .const import DEFAULT_NAME, DEFAULT_URL, DOMAIN
|
from .const import DEFAULT_NAME, DEFAULT_URL, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
@ -25,14 +24,11 @@ class RadarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle a config flow for Radarr."""
|
"""Handle a config flow for Radarr."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
entry: RadarrConfigEntry | 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(
|
||||||
@ -51,10 +47,7 @@ class RadarrConfigFlow(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:
|
|
||||||
# aiopyarr defaults to the service port if one isn't given
|
# aiopyarr defaults to the service port if one isn't given
|
||||||
# this is counter to standard practice where http = 80
|
# this is counter to standard practice where http = 80
|
||||||
# and https = 443.
|
# and https = 443.
|
||||||
@ -75,20 +68,21 @@ class RadarrConfigFlow(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(
|
return self.async_create_entry(
|
||||||
title=DEFAULT_NAME,
|
title=DEFAULT_NAME,
|
||||||
data=user_input,
|
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