mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use reauth helpers in comelit config flow (#127443)
* Use reauth helpers in comelit config flow * Fix
This commit is contained in:
parent
c7739a7760
commit
153b3fbfc8
@ -14,7 +14,7 @@ from aiocomelit.api import ComelitCommonApi
|
|||||||
from aiocomelit.const import BRIDGE
|
from aiocomelit.const import BRIDGE
|
||||||
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_HOST, CONF_PIN, CONF_PORT, CONF_TYPE
|
from homeassistant.const import CONF_HOST, CONF_PIN, CONF_PORT, CONF_TYPE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -68,10 +68,6 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle a config flow for Comelit."""
|
"""Handle a config flow for Comelit."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
_reauth_entry: ConfigEntry
|
|
||||||
_reauth_host: str
|
|
||||||
_reauth_port: int
|
|
||||||
_reauth_type: str
|
|
||||||
|
|
||||||
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
|
||||||
@ -106,12 +102,7 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle reauth flow."""
|
"""Handle reauth flow."""
|
||||||
self._reauth_entry = self._get_reauth_entry()
|
self.context["title_placeholders"] = {"host": entry_data[CONF_HOST]}
|
||||||
self._reauth_host = entry_data[CONF_HOST]
|
|
||||||
self._reauth_port = entry_data.get(CONF_PORT, DEFAULT_PORT)
|
|
||||||
self._reauth_type = entry_data.get(CONF_TYPE, BRIDGE)
|
|
||||||
|
|
||||||
self.context["title_placeholders"] = {"host": self._reauth_host}
|
|
||||||
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(
|
||||||
@ -120,14 +111,17 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle reauth confirm."""
|
"""Handle reauth confirm."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
|
entry_data = reauth_entry.data
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
try:
|
try:
|
||||||
await validate_input(
|
await validate_input(
|
||||||
self.hass,
|
self.hass,
|
||||||
{
|
{
|
||||||
CONF_HOST: self._reauth_host,
|
CONF_HOST: entry_data[CONF_HOST],
|
||||||
CONF_PORT: self._reauth_port,
|
CONF_PORT: entry_data.get(CONF_PORT, DEFAULT_PORT),
|
||||||
CONF_TYPE: self._reauth_type,
|
CONF_TYPE: entry_data.get(CONF_TYPE, BRIDGE),
|
||||||
}
|
}
|
||||||
| user_input,
|
| user_input,
|
||||||
)
|
)
|
||||||
@ -139,23 +133,19 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
else:
|
else:
|
||||||
self.hass.config_entries.async_update_entry(
|
return self.async_update_reload_and_abort(
|
||||||
self._reauth_entry,
|
reauth_entry,
|
||||||
data={
|
data={
|
||||||
CONF_HOST: self._reauth_host,
|
CONF_HOST: entry_data[CONF_HOST],
|
||||||
CONF_PORT: self._reauth_port,
|
CONF_PORT: entry_data.get(CONF_PORT, DEFAULT_PORT),
|
||||||
CONF_PIN: user_input[CONF_PIN],
|
CONF_PIN: user_input[CONF_PIN],
|
||||||
CONF_TYPE: self._reauth_type,
|
CONF_TYPE: entry_data.get(CONF_TYPE, BRIDGE),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.hass.async_create_task(
|
|
||||||
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(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
description_placeholders={CONF_HOST: self._reauth_entry.data[CONF_HOST]},
|
description_placeholders={CONF_HOST: entry_data[CONF_HOST]},
|
||||||
data_schema=STEP_REAUTH_DATA_SCHEMA,
|
data_schema=STEP_REAUTH_DATA_SCHEMA,
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user