Use call_at for events instead call_later (#93431)
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
This commit is contained in:
parent
30d9d7d905
commit
5c6ed8f6d5
2 changed files with 7 additions and 8 deletions
|
@ -1322,6 +1322,7 @@ def async_track_point_in_utc_time(
|
||||||
# Since this is called once, we accept a HassJob so we can avoid
|
# 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.
|
# having to figure out how to call the action every time its called.
|
||||||
cancel_callback: asyncio.TimerHandle | None = None
|
cancel_callback: asyncio.TimerHandle | None = None
|
||||||
|
loop = hass.loop
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def run_action(job: HassJob[[datetime], Coroutine[Any, Any, None] | None]) -> None:
|
def run_action(job: HassJob[[datetime], Coroutine[Any, Any, None] | None]) -> None:
|
||||||
|
@ -1335,7 +1336,7 @@ def async_track_point_in_utc_time(
|
||||||
if (delta := (expected_fire_timestamp - time_tracker_timestamp())) > 0:
|
if (delta := (expected_fire_timestamp - time_tracker_timestamp())) > 0:
|
||||||
_LOGGER.debug("Called %f seconds too early, rearming", delta)
|
_LOGGER.debug("Called %f seconds too early, rearming", delta)
|
||||||
|
|
||||||
cancel_callback = hass.loop.call_later(delta, run_action, job)
|
cancel_callback = loop.call_at(loop.time() + delta, run_action, job)
|
||||||
return
|
return
|
||||||
|
|
||||||
hass.async_run_hass_job(job, utc_point_in_time)
|
hass.async_run_hass_job(job, utc_point_in_time)
|
||||||
|
@ -1346,11 +1347,11 @@ def async_track_point_in_utc_time(
|
||||||
else HassJob(action, f"track point in utc time {utc_point_in_time}")
|
else HassJob(action, f"track point in utc time {utc_point_in_time}")
|
||||||
)
|
)
|
||||||
delta = expected_fire_timestamp - time.time()
|
delta = expected_fire_timestamp - time.time()
|
||||||
cancel_callback = hass.loop.call_later(delta, run_action, job)
|
cancel_callback = loop.call_at(loop.time() + delta, run_action, job)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def unsub_point_in_time_listener() -> None:
|
def unsub_point_in_time_listener() -> None:
|
||||||
"""Cancel the call_later."""
|
"""Cancel the call_at."""
|
||||||
assert cancel_callback is not None
|
assert cancel_callback is not None
|
||||||
cancel_callback.cancel()
|
cancel_callback.cancel()
|
||||||
|
|
||||||
|
@ -1382,7 +1383,7 @@ def async_call_later(
|
||||||
if isinstance(action, HassJob)
|
if isinstance(action, HassJob)
|
||||||
else HassJob(action, f"call_later {delay}")
|
else HassJob(action, f"call_later {delay}")
|
||||||
)
|
)
|
||||||
cancel_callback = hass.loop.call_later(delay, run_action, job)
|
cancel_callback = hass.loop.call_at(hass.loop.time() + delay, run_action, job)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def unsub_call_later_listener() -> None:
|
def unsub_call_later_listener() -> None:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Tests for the Home Assistant auth module."""
|
"""Tests for the Home Assistant auth module."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
import jwt
|
import jwt
|
||||||
|
@ -31,10 +31,8 @@ from tests.common import (
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_hass(event_loop):
|
def mock_hass(hass: HomeAssistant) -> HomeAssistant:
|
||||||
"""Home Assistant mock with minimum amount of data set to make it work with auth."""
|
"""Home Assistant mock with minimum amount of data set to make it work with auth."""
|
||||||
hass = Mock()
|
|
||||||
hass.config.skip_pip = True
|
|
||||||
return hass
|
return hass
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue