Import tag (#64539)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/67132/head
epenet 2022-02-23 18:55:31 +01:00 committed by GitHub
parent 3380a15bbb
commit e37402e1d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -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)

View File

@ -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,