diff --git a/homeassistant/components/esphome/__init__.py b/homeassistant/components/esphome/__init__.py index 7d5736a2e68..0154e2eba28 100644 --- a/homeassistant/components/esphome/__init__.py +++ b/homeassistant/components/esphome/__init__.py @@ -117,7 +117,7 @@ async def async_setup_entry( # noqa: C901 port = entry.data[CONF_PORT] password = entry.data[CONF_PASSWORD] noise_psk = entry.data.get(CONF_NOISE_PSK) - device_id = None + device_id: str | None = None zeroconf_instance = await zeroconf.async_get_instance(hass) @@ -184,11 +184,12 @@ async def async_setup_entry( # noqa: C901 return # Call native tag scan - if service_name == "tag_scanned": + if service_name == "tag_scanned" and device_id is not None: + # Importing tag via hass.components in case it is overridden + # in a custom_components (custom_components.tag) + tag = hass.components.tag tag_id = service_data["tag_id"] - hass.async_create_task( - hass.components.tag.async_scan_tag(tag_id, device_id) - ) + hass.async_create_task(tag.async_scan_tag(tag_id, device_id)) return hass.bus.async_fire(service.service, service_data) diff --git a/homeassistant/components/mqtt/tag.py b/homeassistant/components/mqtt/tag.py index 4f6f380e47d..a2541c064c0 100644 --- a/homeassistant/components/mqtt/tag.py +++ b/homeassistant/components/mqtt/tag.py @@ -177,7 +177,10 @@ class MQTTTagScanner: if not tag_id: # No output from template, ignore return - await self.hass.components.tag.async_scan_tag(tag_id, self.device_id) + # Importing tag via hass.components in case it is overridden + # in a custom_components (custom_components.tag) + tag = self.hass.components.tag + await tag.async_scan_tag(tag_id, self.device_id) self._sub_state = subscription.async_prepare_subscribe_topics( self.hass,