mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Use reauth helpers in caldav config flow (#127440)
This commit is contained in:
parent
255cf6b305
commit
c634f6067a
@ -9,7 +9,7 @@ from caldav.lib.error import AuthorizationError, DAVError
|
|||||||
import requests
|
import requests
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME, CONF_VERIFY_SSL
|
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME, CONF_VERIFY_SSL
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
@ -32,7 +32,6 @@ class CalDavConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle a config flow for caldav."""
|
"""Handle a config flow for caldav."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
_reauth_entry: ConfigEntry
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
@ -91,7 +90,6 @@ class CalDavConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""Perform reauth upon an API authentication error."""
|
||||||
self._reauth_entry = self._get_reauth_entry()
|
|
||||||
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(
|
||||||
@ -99,21 +97,18 @@ class CalDavConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Confirm reauth dialog."""
|
"""Confirm reauth dialog."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
user_input = {**self._reauth_entry.data, **user_input}
|
user_input = {**reauth_entry.data, **user_input}
|
||||||
|
|
||||||
if error := await self._test_connection(user_input):
|
if error := await self._test_connection(user_input):
|
||||||
errors["base"] = error
|
errors["base"] = error
|
||||||
else:
|
else:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(reauth_entry, data=user_input)
|
||||||
self._reauth_entry, data=user_input
|
|
||||||
)
|
|
||||||
await self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
description_placeholders={
|
description_placeholders={
|
||||||
CONF_USERNAME: self._reauth_entry.data[CONF_USERNAME],
|
CONF_USERNAME: reauth_entry.data[CONF_USERNAME],
|
||||||
},
|
},
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user