mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 10:47:51 +00:00
Fix ESPHome scan tag device ID (#40132)
This commit is contained in:
parent
9309297d76
commit
b515480a98
@ -66,6 +66,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
|||||||
host = entry.data[CONF_HOST]
|
host = entry.data[CONF_HOST]
|
||||||
port = entry.data[CONF_PORT]
|
port = entry.data[CONF_PORT]
|
||||||
password = entry.data[CONF_PASSWORD]
|
password = entry.data[CONF_PASSWORD]
|
||||||
|
device_id = None
|
||||||
|
|
||||||
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
||||||
|
|
||||||
@ -134,9 +135,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
|||||||
if service_name == "tag_scanned":
|
if service_name == "tag_scanned":
|
||||||
tag_id = service_data["tag_id"]
|
tag_id = service_data["tag_id"]
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.components.tag.async_scan_tag(
|
hass.components.tag.async_scan_tag(tag_id, device_id)
|
||||||
tag_id, entry_data.device_info.name
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -177,10 +176,13 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
|||||||
|
|
||||||
async def on_login() -> None:
|
async def on_login() -> None:
|
||||||
"""Subscribe to states and list entities on successful API login."""
|
"""Subscribe to states and list entities on successful API login."""
|
||||||
|
nonlocal device_id
|
||||||
try:
|
try:
|
||||||
entry_data.device_info = await cli.device_info()
|
entry_data.device_info = await cli.device_info()
|
||||||
entry_data.available = True
|
entry_data.available = True
|
||||||
await _async_setup_device_registry(hass, entry, entry_data.device_info)
|
device_id = await _async_setup_device_registry(
|
||||||
|
hass, entry, entry_data.device_info
|
||||||
|
)
|
||||||
entry_data.async_update_device_state(hass)
|
entry_data.async_update_device_state(hass)
|
||||||
|
|
||||||
entity_infos, services = await cli.list_entities_services()
|
entity_infos, services = await cli.list_entities_services()
|
||||||
@ -276,7 +278,7 @@ async def _async_setup_device_registry(
|
|||||||
if device_info.compilation_time:
|
if device_info.compilation_time:
|
||||||
sw_version += f" ({device_info.compilation_time})"
|
sw_version += f" ({device_info.compilation_time})"
|
||||||
device_registry = await dr.async_get_registry(hass)
|
device_registry = await dr.async_get_registry(hass)
|
||||||
device_registry.async_get_or_create(
|
entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, device_info.mac_address)},
|
connections={(dr.CONNECTION_NETWORK_MAC, device_info.mac_address)},
|
||||||
name=device_info.name,
|
name=device_info.name,
|
||||||
@ -284,6 +286,7 @@ async def _async_setup_device_registry(
|
|||||||
model=device_info.model,
|
model=device_info.model,
|
||||||
sw_version=sw_version,
|
sw_version=sw_version,
|
||||||
)
|
)
|
||||||
|
return entry.id
|
||||||
|
|
||||||
|
|
||||||
async def _register_service(
|
async def _register_service(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user