This commit is contained in:
J. Nick Koston 2025-04-16 21:01:11 -10:00
parent 07a782df4a
commit 4240d461c4
No known key found for this signature in database

View File

@ -142,7 +142,7 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle reauthorization flow when encryption was removed.""" """Handle reauthorization flow when encryption was removed."""
if user_input is not None: if user_input is not None:
self._noise_psk = None self._noise_psk = None
return await self._async_get_entry_or_resolve_conflict() return await self.async_step_validated_connection()
return self.async_show_form( return self.async_show_form(
step_id="reauth_encryption_removed_confirm", step_id="reauth_encryption_removed_confirm",
@ -244,7 +244,7 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
return await self.async_step_authenticate() return await self.async_step_authenticate()
self._password = "" self._password = ""
return await self._async_get_entry_or_resolve_conflict() return await self.async_step_validated_connection()
async def async_step_discovery_confirm( async def async_step_discovery_confirm(
self, user_input: dict[str, Any] | None = None self, user_input: dict[str, Any] | None = None
@ -438,15 +438,6 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
options=self._async_make_default_options(), options=self._async_make_default_options(),
) )
async def _async_get_entry_or_resolve_conflict(self) -> ConfigFlowResult:
"""Return the entry or resolve a conflict."""
if self.source not in (SOURCE_REAUTH, SOURCE_RECONFIGURE):
for entry in self._async_current_entries(include_ignore=False):
if entry.data.get(CONF_DEVICE_NAME) == self._device_name:
self._entry_with_name_conflict = entry
return await self.async_step_name_conflict()
return await self._async_get_entry()
@callback @callback
def _async_make_config_data(self) -> dict[str, Any]: def _async_make_config_data(self) -> dict[str, Any]:
"""Return config data for the entry.""" """Return config data for the entry."""
@ -466,7 +457,8 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
CONF_ALLOW_SERVICE_CALLS: DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS, CONF_ALLOW_SERVICE_CALLS: DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS,
} }
async def _async_get_entry(self) -> ConfigFlowResult: async def async_step_validated_connection(self) -> ConfigFlowResult:
"""Handle validated connection."""
config_data = self._async_make_config_data() config_data = self._async_make_config_data()
if self.source == SOURCE_RECONFIGURE: if self.source == SOURCE_RECONFIGURE:
assert self.unique_id is not None assert self.unique_id is not None
@ -481,10 +473,10 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
"expected_mac": format_mac(self._reconfig_entry.unique_id), "expected_mac": format_mac(self._reconfig_entry.unique_id),
} }
for entry in self._async_current_entries(include_ignore=False): for entry in self._async_current_entries(include_ignore=False):
if entry.data.get(CONF_DEVICE_NAME) == self._device_name: if (
if entry.entry_id == self._reconfig_entry.entry_id: entry.entry_id != self._reconfig_entry.entry_id
self._entry_with_name_conflict = self._reconfig_entry and entry.data.get(CONF_DEVICE_NAME) == self._device_name
return await self.async_step_name_conflict() ):
return self.async_abort( return self.async_abort(
reason="reconfigure_name_conflict", reason="reconfigure_name_conflict",
description_placeholders={ description_placeholders={
@ -493,6 +485,9 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
}, },
) )
if self._reconfig_entry.unique_id != format_mac(self.unique_id): if self._reconfig_entry.unique_id != format_mac(self.unique_id):
if self._reconfig_entry.data[CONF_DEVICE_NAME] == self._device_name:
self._entry_with_name_conflict = self._reconfig_entry
return await self.async_step_name_conflict()
return self.async_abort( return self.async_abort(
reason="reconfigure_unique_id_changed", reason="reconfigure_unique_id_changed",
description_placeholders={ description_placeholders={
@ -508,7 +503,10 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
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
) )
for entry in self._async_current_entries(include_ignore=False):
if entry.data.get(CONF_DEVICE_NAME) == self._device_name:
self._entry_with_name_conflict = entry
return await self.async_step_name_conflict()
assert self._name is not None assert self._name is not None
return self.async_create_entry( return self.async_create_entry(
title=self._name, title=self._name,
@ -544,7 +542,7 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
error = await self.try_login() error = await self.try_login()
if error: if error:
return await self.async_step_authenticate(error=error) return await self.async_step_authenticate(error=error)
return await self._async_get_entry_or_resolve_conflict() return await self.async_step_validated_connection()
errors = {} errors = {}
if error is not None: if error is not None: