Improve debuggability by providing job as an arg to loop.call_later (#49328)

Before
`<TimerHandle when=1523538.181864923 async_track_point_in_utc_time.<locals>.run_action() at /usr/src/homeassistant/homeassistant/helpers/event.py:1177>`

After
`<TimerHandle when=1524977.1818648616 async_track_point_in_utc_time.<locals>.run_action(<Job HassJobType.Coroutinefunction <bound method DataUpdateCoordinator._handle_refresh_interval of <homeassistant.components.roku.RokuDataUpdateCoordinator object at 0x7fcc978a51c0>>>) at /usr/src/homeassistant/homeassistant/helpers/event.py:1175>`
This commit is contained in:
J. Nick Koston 2021-04-18 23:02:17 -10:00 committed by GitHub
parent 0b26294fb0
commit 6048e88c8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1170,12 +1170,10 @@ def async_track_point_in_utc_time(
# Since this is called once, we accept a HassJob so we can avoid
# having to figure out how to call the action every time its called.
job = action if isinstance(action, HassJob) else HassJob(action)
cancel_callback: asyncio.TimerHandle | None = None
@callback
def run_action() -> None:
def run_action(job: HassJob) -> None:
"""Call the action."""
nonlocal cancel_callback
@ -1190,13 +1188,14 @@ def async_track_point_in_utc_time(
if delta > 0:
_LOGGER.debug("Called %f seconds too early, rearming", delta)
cancel_callback = hass.loop.call_later(delta, run_action)
cancel_callback = hass.loop.call_later(delta, run_action, job)
return
hass.async_run_hass_job(job, utc_point_in_time)
job = action if isinstance(action, HassJob) else HassJob(action)
delta = utc_point_in_time.timestamp() - time.time()
cancel_callback = hass.loop.call_later(delta, run_action)
cancel_callback = hass.loop.call_later(delta, run_action, job)
@callback
def unsub_point_in_time_listener() -> None: