Use new reauth helpers in overkiz (#128666)
* Use reauth_confirm in overkiz * Just use new helpers
This commit is contained in:
parent
8c4b076746
commit
d6703b20d3
1 changed files with 14 additions and 50 deletions
|
@ -24,7 +24,7 @@ from pyoverkiz.utils import generate_local_server, is_overkiz_gateway
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import dhcp, zeroconf
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
|
@ -47,7 +47,6 @@ class OverkizConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 1
|
||||
|
||||
_reauth_entry: ConfigEntry | None = None
|
||||
_api_type: APIType = APIType.CLOUD
|
||||
_user: str | None = None
|
||||
_server: str = DEFAULT_SERVER
|
||||
|
@ -174,27 +173,13 @@ class OverkizConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
errors["base"] = "unknown"
|
||||
LOGGER.exception("Unknown error")
|
||||
else:
|
||||
if self._reauth_entry:
|
||||
if self._reauth_entry.unique_id != self.unique_id:
|
||||
return self.async_abort(reason="reauth_wrong_account")
|
||||
if self.source == SOURCE_REAUTH:
|
||||
self._abort_if_unique_id_mismatch(reason="reauth_wrong_account")
|
||||
|
||||
# Update existing entry during reauth
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self._reauth_entry,
|
||||
data={
|
||||
**self._reauth_entry.data,
|
||||
**user_input,
|
||||
},
|
||||
return self.async_update_reload_and_abort(
|
||||
self._get_reauth_entry(), data_updates=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")
|
||||
|
||||
# Create new entry
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
|
@ -257,27 +242,13 @@ class OverkizConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
errors["base"] = "unknown"
|
||||
LOGGER.exception("Unknown error")
|
||||
else:
|
||||
if self._reauth_entry:
|
||||
if self._reauth_entry.unique_id != self.unique_id:
|
||||
return self.async_abort(reason="reauth_wrong_account")
|
||||
if self.source == SOURCE_REAUTH:
|
||||
self._abort_if_unique_id_mismatch(reason="reauth_wrong_account")
|
||||
|
||||
# Update existing entry during reauth
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self._reauth_entry,
|
||||
data={
|
||||
**self._reauth_entry.data,
|
||||
**user_input,
|
||||
},
|
||||
return self.async_update_reload_and_abort(
|
||||
self._get_reauth_entry(), data_updates=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")
|
||||
|
||||
# Create new entry
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
|
@ -346,22 +317,15 @@ class OverkizConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle reauth."""
|
||||
self._reauth_entry = cast(
|
||||
ConfigEntry,
|
||||
self.hass.config_entries.async_get_entry(self.context["entry_id"]),
|
||||
)
|
||||
|
||||
# overkiz entries always have unique IDs
|
||||
self.context["title_placeholders"] = {
|
||||
"gateway_id": cast(str, self._reauth_entry.unique_id)
|
||||
}
|
||||
self.context["title_placeholders"] = {"gateway_id": cast(str, self.unique_id)}
|
||||
|
||||
self._user = self._reauth_entry.data[CONF_USERNAME]
|
||||
self._server = self._reauth_entry.data[CONF_HUB]
|
||||
self._api_type = self._reauth_entry.data.get(CONF_API_TYPE, APIType.CLOUD)
|
||||
self._user = entry_data[CONF_USERNAME]
|
||||
self._server = entry_data[CONF_HUB]
|
||||
self._api_type = entry_data.get(CONF_API_TYPE, APIType.CLOUD)
|
||||
|
||||
if self._api_type == APIType.LOCAL:
|
||||
self._host = self._reauth_entry.data[CONF_HOST]
|
||||
self._host = entry_data[CONF_HOST]
|
||||
|
||||
return await self.async_step_user(dict(entry_data))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue