mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use new reauth helpers in vicare (#128779)
This commit is contained in:
parent
2bc642ae6f
commit
7fa359764d
@ -13,7 +13,7 @@ from PyViCare.PyViCareUtils import (
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import dhcp
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_CLIENT_ID, CONF_PASSWORD, CONF_USERNAME
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
@ -50,7 +50,6 @@ class ViCareConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for ViCare."""
|
||||
|
||||
VERSION = 1
|
||||
entry: ConfigEntry | None
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
@ -81,7 +80,6 @@ class ViCareConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle re-authentication with ViCare."""
|
||||
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(
|
||||
@ -89,11 +87,11 @@ class ViCareConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
) -> ConfigFlowResult:
|
||||
"""Confirm re-authentication with ViCare."""
|
||||
errors: dict[str, str] = {}
|
||||
assert self.entry is not None
|
||||
|
||||
reauth_entry = self._get_reauth_entry()
|
||||
if user_input:
|
||||
data = {
|
||||
**self.entry.data,
|
||||
**reauth_entry.data,
|
||||
**user_input,
|
||||
}
|
||||
|
||||
@ -102,17 +100,12 @@ class ViCareConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
except (PyViCareInvalidConfigurationError, PyViCareInvalidCredentialsError):
|
||||
errors["base"] = "invalid_auth"
|
||||
else:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.entry,
|
||||
data=data,
|
||||
)
|
||||
await self.hass.config_entries.async_reload(self.entry.entry_id)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
return self.async_update_reload_and_abort(reauth_entry, data=data)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="reauth_confirm",
|
||||
data_schema=self.add_suggested_values_to_schema(
|
||||
REAUTH_SCHEMA, self.entry.data
|
||||
REAUTH_SCHEMA, reauth_entry.data
|
||||
),
|
||||
errors=errors,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user