mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Use new reauth_helpers in nextcloud (#128700)
This commit is contained in:
parent
81b918c392
commit
dd8f1800df
@ -13,7 +13,7 @@ from nextcloudmonitor import (
|
||||
)
|
||||
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 .const import DEFAULT_VERIFY_SSL, DOMAIN
|
||||
@ -39,8 +39,6 @@ class NextcloudConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
VERSION = 1
|
||||
|
||||
_entry: ConfigEntry | None = None
|
||||
|
||||
def _try_connect_nc(self, user_input: dict) -> NextcloudMonitor:
|
||||
"""Try to connect to nextcloud server."""
|
||||
return NextcloudMonitor(
|
||||
@ -79,7 +77,6 @@ class NextcloudConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle flow upon an API authentication error."""
|
||||
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(
|
||||
@ -87,32 +84,29 @@ class NextcloudConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle reauthorization flow."""
|
||||
errors = {}
|
||||
assert self._entry is not None
|
||||
|
||||
reauth_entry = self._get_reauth_entry()
|
||||
if user_input is not None:
|
||||
try:
|
||||
await self.hass.async_add_executor_job(
|
||||
self._try_connect_nc, {**self._entry.data, **user_input}
|
||||
self._try_connect_nc, {**reauth_entry.data, **user_input}
|
||||
)
|
||||
except NextcloudMonitorAuthorizationError:
|
||||
errors["base"] = "invalid_auth"
|
||||
except (NextcloudMonitorConnectionError, NextcloudMonitorRequestError):
|
||||
errors["base"] = "connection_error"
|
||||
else:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self._entry,
|
||||
data={**self._entry.data, **user_input},
|
||||
return self.async_update_reload_and_abort(
|
||||
reauth_entry, data_updates=user_input
|
||||
)
|
||||
await self.hass.config_entries.async_reload(self._entry.entry_id)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
|
||||
data_schema = self.add_suggested_values_to_schema(
|
||||
DATA_SCHEMA_REAUTH,
|
||||
{CONF_USERNAME: self._entry.data[CONF_USERNAME], **(user_input or {})},
|
||||
{CONF_USERNAME: reauth_entry.data[CONF_USERNAME], **(user_input or {})},
|
||||
)
|
||||
return self.async_show_form(
|
||||
step_id="reauth_confirm",
|
||||
data_schema=data_schema,
|
||||
description_placeholders={"url": self._entry.data[CONF_URL]},
|
||||
description_placeholders={"url": reauth_entry.data[CONF_URL]},
|
||||
errors=errors,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user