mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use reauth helpers in esphome config flow (#127419)
Use _get_reauth_entry in esphome config flow
This commit is contained in:
parent
9ba58233ec
commit
a218f4adc3
@ -23,6 +23,7 @@ import voluptuous as vol
|
|||||||
from homeassistant.components import dhcp, zeroconf
|
from homeassistant.components import dhcp, zeroconf
|
||||||
from homeassistant.components.hassio import HassioServiceInfo
|
from homeassistant.components.hassio import HassioServiceInfo
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
|
SOURCE_REAUTH,
|
||||||
ConfigEntry,
|
ConfigEntry,
|
||||||
ConfigFlow,
|
ConfigFlow,
|
||||||
ConfigFlowResult,
|
ConfigFlowResult,
|
||||||
@ -57,6 +58,8 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
|
_reauth_entry: ConfigEntry
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize flow."""
|
"""Initialize flow."""
|
||||||
self._host: str | None = None
|
self._host: str | None = None
|
||||||
@ -66,7 +69,6 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self._noise_required: bool | None = None
|
self._noise_required: bool | None = None
|
||||||
self._noise_psk: str | None = None
|
self._noise_psk: str | None = None
|
||||||
self._device_info: DeviceInfo | None = None
|
self._device_info: DeviceInfo | None = None
|
||||||
self._reauth_entry: ConfigEntry | None = None
|
|
||||||
# The ESPHome name as per its config
|
# The ESPHome name as per its config
|
||||||
self._device_name: str | None = None
|
self._device_name: str | None = None
|
||||||
|
|
||||||
@ -103,14 +105,12 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle a flow initialized by a reauth event."""
|
"""Handle a flow initialized by a reauth event."""
|
||||||
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
self._reauth_entry = self._get_reauth_entry()
|
||||||
assert entry is not None
|
self._host = entry_data[CONF_HOST]
|
||||||
self._reauth_entry = entry
|
self._port = entry_data[CONF_PORT]
|
||||||
self._host = entry.data[CONF_HOST]
|
self._password = entry_data[CONF_PASSWORD]
|
||||||
self._port = entry.data[CONF_PORT]
|
self._name = self._reauth_entry.title
|
||||||
self._password = entry.data[CONF_PASSWORD]
|
self._device_name = entry_data.get(CONF_DEVICE_NAME)
|
||||||
self._name = entry.title
|
|
||||||
self._device_name = entry.data.get(CONF_DEVICE_NAME)
|
|
||||||
|
|
||||||
# Device without encryption allows fetching device info. We can then check
|
# Device without encryption allows fetching device info. We can then check
|
||||||
# if the device is no longer using a password. If we did try with a password,
|
# if the device is no longer using a password. If we did try with a password,
|
||||||
@ -324,7 +324,7 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
config_options = {
|
config_options = {
|
||||||
CONF_ALLOW_SERVICE_CALLS: DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS,
|
CONF_ALLOW_SERVICE_CALLS: DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS,
|
||||||
}
|
}
|
||||||
if self._reauth_entry:
|
if self.source == SOURCE_REAUTH:
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self._reauth_entry, data=self._reauth_entry.data | config_data
|
self._reauth_entry, data=self._reauth_entry.data | config_data
|
||||||
)
|
)
|
||||||
@ -411,7 +411,7 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
self._device_name = self._device_info.name
|
self._device_name = self._device_info.name
|
||||||
mac_address = format_mac(self._device_info.mac_address)
|
mac_address = format_mac(self._device_info.mac_address)
|
||||||
await self.async_set_unique_id(mac_address, raise_on_progress=False)
|
await self.async_set_unique_id(mac_address, raise_on_progress=False)
|
||||||
if not self._reauth_entry:
|
if self.source != SOURCE_REAUTH:
|
||||||
self._abort_if_unique_id_configured(
|
self._abort_if_unique_id_configured(
|
||||||
updates={CONF_HOST: self._host, CONF_PORT: self._port}
|
updates={CONF_HOST: self._host, CONF_PORT: self._port}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user