diff --git a/homeassistant/components/esphome/config_flow.py b/homeassistant/components/esphome/config_flow.py index fc81dfdbc432..9fcad5aa4f1c 100644 --- a/homeassistant/components/esphome/config_flow.py +++ b/homeassistant/components/esphome/config_flow.py @@ -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 ) diff --git a/tests/components/esphome/test_config_flow.py b/tests/components/esphome/test_config_flow.py index fb7458a1a5b7..0dbab47b6f56 100644 --- a/tests/components/esphome/test_config_flow.py +++ b/tests/components/esphome/test_config_flow.py @@ -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"