diff --git a/homeassistant/components/esphome/config_flow.py b/homeassistant/components/esphome/config_flow.py index ca1b2be3689..5ef08f126d4 100644 --- a/homeassistant/components/esphome/config_flow.py +++ b/homeassistant/components/esphome/config_flow.py @@ -452,23 +452,38 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN): CONF_NOISE_PSK: self._noise_psk or "", CONF_DEVICE_NAME: self._device_name, } - config_options = { - CONF_ALLOW_SERVICE_CALLS: DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS, - } + if self.source == SOURCE_RECONFIGURE: assert self.unique_id is not None assert self._reconfig_entry.unique_id is not None assert self._host is not None assert self._device_name is not None + placeholders = { + "name": self._reconfig_entry.data.get( + CONF_DEVICE_NAME, self._reconfig_entry.title + ), + "host": self._host, + "expected_mac": format_mac(self._reconfig_entry.unique_id), + } + for entry in self._async_current_entries(include_ignore=False): + if ( + entry.entry_id != self._reconfig_entry.entry_id + and entry.data.get(CONF_DEVICE_NAME) == self._device_name + ): + return self.async_abort( + reason="reconfigure_name_conflict", + description_placeholders={ + **placeholders, + "existing_title": entry.title, + }, + ) if self._reconfig_entry.unique_id != format_mac(self.unique_id): return self.async_abort( reason="reconfigure_unique_id_changed", description_placeholders={ - "name": self._reconfig_entry.title, - "host": self._host, - "expected_mac": format_mac(self._reconfig_entry.unique_id), - "unexpected_device_name": self._device_name, + **placeholders, "unexpected_mac": format_mac(self.unique_id), + "unexpected_device_name": self._device_name, }, ) return self.async_update_reload_and_abort( @@ -483,7 +498,9 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN): return self.async_create_entry( title=self._name, data=config_data, - options=config_options, + options={ + CONF_ALLOW_SERVICE_CALLS: DEFAULT_NEW_CONFIG_ALLOW_ALLOW_SERVICE_CALLS, + }, ) async def async_step_encryption_key( diff --git a/homeassistant/components/esphome/strings.json b/homeassistant/components/esphome/strings.json index 88c4ff4cbc3..fbe8496c9be 100644 --- a/homeassistant/components/esphome/strings.json +++ b/homeassistant/components/esphome/strings.json @@ -12,6 +12,7 @@ "mqtt_missing_payload": "Missing MQTT Payload.", "name_conflict_migrated": "The configuration for `{name}` has been migrated to a new device with MAC address `{mac}` from `{existing_mac}`.", "reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]", + "reconfigure_name_conflict": "**Reconfiguration of `{name}` was aborted** because the address `{host}` points to a device named `{name}` (MAC: `{expected_mac}`), which is already in use by another configuration entry: `{existing_title}`.", "reconfigure_unique_id_changed": "**Reconfiguration of `{name}` was aborted** because the address `{host}` points to a different device: `{unexpected_device_name}` (MAC: `{unexpected_mac}`) instead of the expected one (MAC: `{expected_mac}`)." }, "error": {