Fix reconfigure flow in esphome uses create_entry (#154107)

This commit is contained in:
G Johansson
2025-10-14 13:46:53 +02:00
committed by GitHub
parent 106a74c954
commit cdc6c44a49
2 changed files with 18 additions and 10 deletions

View File

@@ -500,6 +500,16 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
) -> ConfigFlowResult:
"""Handle creating a new entry by removing the old one and creating new."""
assert self._entry_with_name_conflict is not None
if self.source in (SOURCE_REAUTH, SOURCE_RECONFIGURE):
return self.async_update_reload_and_abort(
self._entry_with_name_conflict,
title=self._name,
unique_id=self.unique_id,
data=self._async_make_config_data(),
options={
CONF_ALLOW_SERVICE_CALLS: DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS,
},
)
await self.hass.config_entries.async_remove(
self._entry_with_name_conflict.entry_id
)

View File

@@ -2208,7 +2208,6 @@ async def test_user_flow_name_conflict_overwrite(
result["flow_id"], user_input={"next_step_id": "name_conflict_overwrite"}
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] == {
CONF_HOST: "127.0.0.1",
CONF_PORT: 6053,
@@ -2572,16 +2571,15 @@ async def test_reconfig_name_conflict_overwrite(
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={"next_step_id": "name_conflict_overwrite"}
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_successful"
assert result["data"] == {
CONF_HOST: "127.0.0.2",
CONF_PORT: 6053,
CONF_PASSWORD: "",
CONF_NOISE_PSK: "",
CONF_DEVICE_NAME: "test",
}
assert result["context"]["unique_id"] == "11:22:33:44:55:bb"
assert (
hass.config_entries.async_entry_for_domain_unique_id(
DOMAIN, "11:22:33:44:55:bb"
)
is not None
)
assert (
hass.config_entries.async_entry_for_domain_unique_id(
DOMAIN, "11:22:33:44:55:aa"