1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-22 20:09:35 +00:00
Files
core/tests/patch_time.py
2024-04-27 07:08:56 -05:00

29 lines
775 B
Python

"""Patch time related functions."""
from __future__ import annotations
import datetime
import time
from homeassistant import runner, util
from homeassistant.helpers import event as event_helper
from homeassistant.util import dt as dt_util
def _utcnow() -> datetime.datetime:
"""Make utcnow patchable by freezegun."""
return datetime.datetime.now(datetime.UTC)
def _monotonic() -> float:
"""Make monotonic patchable by freezegun."""
return time.monotonic()
# Replace partial functions which are not found by freezegun
dt_util.utcnow = _utcnow # type: ignore[assignment]
event_helper.time_tracker_utcnow = _utcnow # type: ignore[assignment]
util.utcnow = _utcnow # type: ignore[assignment]
runner.monotonic = _monotonic # type: ignore[assignment]