mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Avoid creating task per device when adding legacy device trackers (#111220)
This commit is contained in:
parent
5f8ef37f2d
commit
40774101d3
@ -714,21 +714,17 @@ class DeviceTracker:
|
|||||||
|
|
||||||
This method is a coroutine.
|
This method is a coroutine.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def async_init_single_device(dev: Device) -> None:
|
|
||||||
"""Init a single device_tracker entity."""
|
|
||||||
await dev.async_added_to_hass()
|
|
||||||
dev.async_write_ha_state()
|
|
||||||
|
|
||||||
tasks: list[asyncio.Task] = []
|
|
||||||
for device in self.devices.values():
|
for device in self.devices.values():
|
||||||
if device.track and not device.last_seen:
|
if device.track and not device.last_seen:
|
||||||
tasks.append(
|
# async_added_to_hass is unlikely to suspend so
|
||||||
self.hass.async_create_task(async_init_single_device(device))
|
# do not gather here to avoid unnecessary overhead
|
||||||
)
|
# of creating a task per device.
|
||||||
|
#
|
||||||
if tasks:
|
# We used to have the overhead of potentially loading
|
||||||
await asyncio.wait(tasks)
|
# restore state for each device here, but RestoreState
|
||||||
|
# is always loaded ahead of time now.
|
||||||
|
await device.async_added_to_hass()
|
||||||
|
device.async_write_ha_state()
|
||||||
|
|
||||||
|
|
||||||
class Device(RestoreEntity):
|
class Device(RestoreEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user