Migrate legacy device_tracker task creation to use eager_start (#114703)

Many of these can finish synchronously without being scheduled on the loop
pull/114741/head
J. Nick Koston 2024-04-03 00:12:52 -10:00 committed by GitHub
parent e870d420a6
commit 742643936f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 4 deletions

View File

@ -524,7 +524,7 @@ def async_setup_scanner_platform(
]
kwargs["gps_accuracy"] = 0
hass.async_create_task(async_see_device(**kwargs))
hass.async_create_task(async_see_device(**kwargs), eager_start=True)
cancel_legacy_scan = async_track_time_interval(
hass,
@ -532,7 +532,7 @@ def async_setup_scanner_platform(
interval,
name=f"device_tracker {platform} legacy scan",
)
hass.async_create_task(async_device_tracker_scan(None))
hass.async_create_task(async_device_tracker_scan(None), eager_start=True)
@callback
def _on_hass_stop(_: Event) -> None:
@ -722,7 +722,8 @@ class DeviceTracker:
self.hass.async_create_task(
self.async_update_config(
self.hass.config.path(YAML_DEVICES), dev_id, device
)
),
eager_start=True,
)
async def async_update_config(self, path: str, dev_id: str, device: Device) -> None:
@ -743,7 +744,9 @@ class DeviceTracker:
"""
for device in self.devices.values():
if (device.track and device.last_update_home) and device.stale(now):
self.hass.async_create_task(device.async_update_ha_state(True))
self.hass.async_create_task(
device.async_update_ha_state(True), eager_start=True
)
async def async_setup_tracked_device(self) -> None:
"""Set up all not exists tracked devices.