Skip to content

Commit cdc6c44

Browse files
Fix reconfigure flow in esphome uses create_entry (home-assistant#154107)
1 parent 106a74c commit cdc6c44

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

homeassistant/components/esphome/config_flow.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,16 @@ async def async_step_name_conflict_overwrite(
500500
) -> ConfigFlowResult:
501501
"""Handle creating a new entry by removing the old one and creating new."""
502502
assert self._entry_with_name_conflict is not None
503+
if self.source in (SOURCE_REAUTH, SOURCE_RECONFIGURE):
504+
return self.async_update_reload_and_abort(
505+
self._entry_with_name_conflict,
506+
title=self._name,
507+
unique_id=self.unique_id,
508+
data=self._async_make_config_data(),
509+
options={
510+
CONF_ALLOW_SERVICE_CALLS: DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS,
511+
},
512+
)
503513
await self.hass.config_entries.async_remove(
504514
self._entry_with_name_conflict.entry_id
505515
)

tests/components/esphome/test_config_flow.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,7 +2208,6 @@ async def test_user_flow_name_conflict_overwrite(
22082208
result["flow_id"], user_input={"next_step_id": "name_conflict_overwrite"}
22092209
)
22102210
assert result["type"] is FlowResultType.CREATE_ENTRY
2211-
22122211
assert result["data"] == {
22132212
CONF_HOST: "127.0.0.1",
22142213
CONF_PORT: 6053,
@@ -2572,16 +2571,15 @@ async def test_reconfig_name_conflict_overwrite(
25722571
result = await hass.config_entries.flow.async_configure(
25732572
result["flow_id"], user_input={"next_step_id": "name_conflict_overwrite"}
25742573
)
2575-
assert result["type"] is FlowResultType.CREATE_ENTRY
2574+
assert result["type"] is FlowResultType.ABORT
2575+
assert result["reason"] == "reconfigure_successful"
25762576

2577-
assert result["data"] == {
2578-
CONF_HOST: "127.0.0.2",
2579-
CONF_PORT: 6053,
2580-
CONF_PASSWORD: "",
2581-
CONF_NOISE_PSK: "",
2582-
CONF_DEVICE_NAME: "test",
2583-
}
2584-
assert result["context"]["unique_id"] == "11:22:33:44:55:bb"
2577+
assert (
2578+
hass.config_entries.async_entry_for_domain_unique_id(
2579+
DOMAIN, "11:22:33:44:55:bb"
2580+
)
2581+
is not None
2582+
)
25852583
assert (
25862584
hass.config_entries.async_entry_for_domain_unique_id(
25872585
DOMAIN, "11:22:33:44:55:aa"

0 commit comments

Comments
 (0)