mirror of
https://github.com/home-assistant/core.git
synced 2025-08-09 15:45:08 +02:00
make patching of time targetable
This commit is contained in:
@@ -564,6 +564,9 @@ def async_track_sunset(
|
|||||||
|
|
||||||
track_sunset = threaded_listener_factory(async_track_sunset)
|
track_sunset = threaded_listener_factory(async_track_sunset)
|
||||||
|
|
||||||
|
# For targeted patching in tests
|
||||||
|
pattern_utc_now = dt_util.utcnow
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@bind_hass
|
@bind_hass
|
||||||
@@ -613,7 +616,7 @@ def async_track_utc_time_change(
|
|||||||
"""Listen for matching time_changed events."""
|
"""Listen for matching time_changed events."""
|
||||||
nonlocal next_time, last_now, cancel_callback
|
nonlocal next_time, last_now, cancel_callback
|
||||||
|
|
||||||
now = dt_util.utcnow()
|
now = pattern_utc_now()
|
||||||
|
|
||||||
if now < last_now:
|
if now < last_now:
|
||||||
# Time rolled back
|
# Time rolled back
|
||||||
|
@@ -300,7 +300,8 @@ def async_fire_time_changed(hass, datetime_):
|
|||||||
|
|
||||||
if mock_seconds_into_future >= future_seconds:
|
if mock_seconds_into_future >= future_seconds:
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.util.dt.utcnow", return_value=date_util.as_utc(datetime_)
|
"homeassistant.helpers.event.pattern_utc_now",
|
||||||
|
return_value=date_util.as_utc(datetime_),
|
||||||
):
|
):
|
||||||
task._run()
|
task._run()
|
||||||
task.cancel()
|
task.cancel()
|
||||||
|
Reference in New Issue
Block a user