make patching of time targetable

This commit is contained in:
J. Nick Koston
2020-07-20 19:20:35 +00:00
parent f9c43f0d65
commit ff7a443d9f
2 changed files with 6 additions and 2 deletions

View File

@@ -564,6 +564,9 @@ def async_track_sunset(
track_sunset = threaded_listener_factory(async_track_sunset)
# For targeted patching in tests
pattern_utc_now = dt_util.utcnow
@callback
@bind_hass
@@ -613,7 +616,7 @@ def async_track_utc_time_change(
"""Listen for matching time_changed events."""
nonlocal next_time, last_now, cancel_callback
now = dt_util.utcnow()
now = pattern_utc_now()
if now < last_now:
# Time rolled back

View File

@@ -300,7 +300,8 @@ def async_fire_time_changed(hass, datetime_):
if mock_seconds_into_future >= future_seconds:
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.cancel()