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
1 changed files with 14 additions and 24 deletions
|
@ -14,7 +14,7 @@ from aiocomelit.api import ComelitCommonApi
|
|||
from aiocomelit.const import BRIDGE
|
||||
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.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
@ -68,10 +68,6 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
"""Handle a config flow for Comelit."""
|
||||
|
||||
VERSION = 1
|
||||
_reauth_entry: ConfigEntry
|
||||
_reauth_host: str
|
||||
_reauth_port: int
|
||||
_reauth_type: str
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
|
@ -106,12 +102,7 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle reauth flow."""
|
||||
self._reauth_entry = self._get_reauth_entry()
|
||||
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}
|
||||
self.context["title_placeholders"] = {"host": entry_data[CONF_HOST]}
|
||||
return await self.async_step_reauth_confirm()
|
||||
|
||||
async def async_step_reauth_confirm(
|
||||
|
@ -120,14 +111,17 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
"""Handle reauth confirm."""
|
||||
errors = {}
|
||||
|
||||
reauth_entry = self._get_reauth_entry()
|
||||
entry_data = reauth_entry.data
|
||||
|
||||
if user_input is not None:
|
||||
try:
|
||||
await validate_input(
|
||||
self.hass,
|
||||
{
|
||||
CONF_HOST: self._reauth_host,
|
||||
CONF_PORT: self._reauth_port,
|
||||
CONF_TYPE: self._reauth_type,
|
||||
CONF_HOST: entry_data[CONF_HOST],
|
||||
CONF_PORT: entry_data.get(CONF_PORT, DEFAULT_PORT),
|
||||
CONF_TYPE: entry_data.get(CONF_TYPE, BRIDGE),
|
||||
}
|
||||
| user_input,
|
||||
)
|
||||
|
@ -139,23 +133,19 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
else:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self._reauth_entry,
|
||||
return self.async_update_reload_and_abort(
|
||||
reauth_entry,
|
||||
data={
|
||||
CONF_HOST: self._reauth_host,
|
||||
CONF_PORT: self._reauth_port,
|
||||
CONF_HOST: entry_data[CONF_HOST],
|
||||
CONF_PORT: entry_data.get(CONF_PORT, DEFAULT_PORT),
|
||||
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(
|
||||
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,
|
||||
errors=errors,
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue