mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Avoid time traveling in recorder tests (#80247)
This commit is contained in:
parent
4462f2fc46
commit
acb1477673
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime
|
||||||
import time
|
import time
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
@ -21,8 +21,6 @@ from homeassistant.util import dt as dt_util
|
|||||||
|
|
||||||
from . import db_schema_0
|
from . import db_schema_0
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed, fire_time_changed
|
|
||||||
|
|
||||||
DEFAULT_PURGE_TASKS = 3
|
DEFAULT_PURGE_TASKS = 3
|
||||||
|
|
||||||
|
|
||||||
@ -69,9 +67,7 @@ def wait_recording_done(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
def trigger_db_commit(hass: HomeAssistant) -> None:
|
def trigger_db_commit(hass: HomeAssistant) -> None:
|
||||||
"""Force the recorder to commit."""
|
"""Force the recorder to commit."""
|
||||||
for _ in range(recorder.DEFAULT_COMMIT_INTERVAL):
|
recorder.get_instance(hass)._async_commit(dt_util.utcnow())
|
||||||
# We only commit on time change
|
|
||||||
fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=1))
|
|
||||||
|
|
||||||
|
|
||||||
async def async_wait_recording_done(hass: HomeAssistant) -> None:
|
async def async_wait_recording_done(hass: HomeAssistant) -> None:
|
||||||
@ -100,8 +96,7 @@ async def async_wait_purge_done(hass: HomeAssistant, max: int = None) -> None:
|
|||||||
@ha.callback
|
@ha.callback
|
||||||
def async_trigger_db_commit(hass: HomeAssistant) -> None:
|
def async_trigger_db_commit(hass: HomeAssistant) -> None:
|
||||||
"""Force the recorder to commit. Async friendly."""
|
"""Force the recorder to commit. Async friendly."""
|
||||||
for _ in range(recorder.DEFAULT_COMMIT_INTERVAL):
|
recorder.get_instance(hass)._async_commit(dt_util.utcnow())
|
||||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=1))
|
|
||||||
|
|
||||||
|
|
||||||
async def async_recorder_block_till_done(hass: HomeAssistant) -> None:
|
async def async_recorder_block_till_done(hass: HomeAssistant) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user