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

Many of these can finish synchronously without being scheduled on the loop
This commit is contained in:
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

View File

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