diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index 38d811c2afd..4c06b0f23e0 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -1322,6 +1322,7 @@ 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. cancel_callback: asyncio.TimerHandle | None = None + loop = hass.loop @callback 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: _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 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}") ) 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 def unsub_point_in_time_listener() -> None: - """Cancel the call_later.""" + """Cancel the call_at.""" assert cancel_callback is not None cancel_callback.cancel() @@ -1382,7 +1383,7 @@ def async_call_later( if isinstance(action, HassJob) 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 def unsub_call_later_listener() -> None: diff --git a/tests/auth/test_init.py b/tests/auth/test_init.py index 83c08dd73ee..3cead230b1b 100644 --- a/tests/auth/test_init.py +++ b/tests/auth/test_init.py @@ -1,7 +1,7 @@ """Tests for the Home Assistant auth module.""" from datetime import timedelta from typing import Any -from unittest.mock import Mock, patch +from unittest.mock import patch from freezegun import freeze_time import jwt @@ -31,10 +31,8 @@ from tests.common import ( @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.""" - hass = Mock() - hass.config.skip_pip = True return hass