mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use new reauth helpers in wallbox (#128820)
This commit is contained in:
parent
b588bd6e4f
commit
e8acb48b1e
@ -8,7 +8,7 @@ from typing import Any
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from wallbox import Wallbox
|
from wallbox import Wallbox
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
@ -43,18 +43,10 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
|
|||||||
class WallboxConfigFlow(ConfigFlow, domain=COMPONENT_DOMAIN):
|
class WallboxConfigFlow(ConfigFlow, domain=COMPONENT_DOMAIN):
|
||||||
"""Handle a config flow for Wallbox."""
|
"""Handle a config flow for Wallbox."""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
"""Start the Wallbox config flow."""
|
|
||||||
self._reauth_entry: ConfigEntry | 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:
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""Perform reauth upon an API authentication error."""
|
||||||
self._reauth_entry = self.hass.config_entries.async_get_entry(
|
|
||||||
self.context["entry_id"]
|
|
||||||
)
|
|
||||||
|
|
||||||
return await self.async_step_user()
|
return await self.async_step_user()
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
@ -71,18 +63,13 @@ class WallboxConfigFlow(ConfigFlow, domain=COMPONENT_DOMAIN):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await self.async_set_unique_id(user_input["station"])
|
await self.async_set_unique_id(user_input["station"])
|
||||||
if not self._reauth_entry:
|
if self.source != SOURCE_REAUTH:
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
info = await validate_input(self.hass, user_input)
|
info = await validate_input(self.hass, user_input)
|
||||||
return self.async_create_entry(title=info["title"], data=user_input)
|
return self.async_create_entry(title=info["title"], data=user_input)
|
||||||
if user_input["station"] == self._reauth_entry.data[CONF_STATION]:
|
reauth_entry = self._get_reauth_entry()
|
||||||
self.hass.config_entries.async_update_entry(
|
if user_input["station"] == reauth_entry.data[CONF_STATION]:
|
||||||
self._reauth_entry, data=user_input, unique_id=user_input["station"]
|
return self.async_update_reload_and_abort(reauth_entry, data=user_input)
|
||||||
)
|
|
||||||
self.hass.async_create_task(
|
|
||||||
self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
|
|
||||||
)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
errors["base"] = "reauth_invalid"
|
errors["base"] = "reauth_invalid"
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user