Remove helper.recorder.async_wait_recorder (#138935)

This commit is contained in:
Erik Montnemery 2025-02-20 16:02:22 +01:00 committed by GitHub
parent b856de225d
commit fb57284561
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 16 additions and 19 deletions

View File

@ -60,16 +60,6 @@ def async_initialize_recorder(hass: HomeAssistant) -> None:
async_setup(hass)
async def async_wait_recorder(hass: HomeAssistant) -> bool:
"""Wait for recorder to initialize and return connection status.
Returns False immediately if the recorder is not enabled.
"""
if DOMAIN not in hass.data:
return False
return await hass.data[DOMAIN].db_connected
@functools.lru_cache(maxsize=1)
def get_instance(hass: HomeAssistant) -> Recorder:
"""Get the recorder instance."""

View File

@ -37,6 +37,7 @@ from homeassistant.components.recorder.db_schema import (
from homeassistant.components.recorder.tasks import RecorderTask, StatisticsTask
from homeassistant.const import UnitOfTemperature
from homeassistant.core import Event, HomeAssistant, State
from homeassistant.helpers import recorder as recorder_helper
from homeassistant.util import dt as dt_util
from . import db_schema_0
@ -79,6 +80,11 @@ async def async_block_recorder(hass: HomeAssistant, seconds: float) -> None:
await event.wait()
async def async_wait_recorder(hass: HomeAssistant) -> bool:
"""Wait for recorder to initialize and return connection status."""
return await hass.data[recorder_helper.DOMAIN].db_connected
def get_start_time(start: datetime) -> datetime:
"""Calculate a valid start time for statistics."""
start_minutes = start.minute - start.minute % 5

View File

@ -85,6 +85,7 @@ from homeassistant.util.json import json_loads
from .common import (
async_block_recorder,
async_recorder_block_till_done,
async_wait_recorder,
async_wait_recording_done,
convert_pending_states_to_meta,
corrupt_db_file,
@ -155,7 +156,7 @@ async def test_shutdown_before_startup_finishes(
recorder_helper.async_initialize_recorder(hass)
hass.async_create_task(async_setup_recorder_instance(hass, config))
await recorder_helper.async_wait_recorder(hass)
await async_wait_recorder(hass)
instance = get_instance(hass)
session = await instance.async_add_executor_job(instance.get_session)
@ -188,7 +189,7 @@ async def test_canceled_before_startup_finishes(
hass.set_state(CoreState.not_running)
recorder_helper.async_initialize_recorder(hass)
hass.async_create_task(async_setup_recorder_instance(hass))
await recorder_helper.async_wait_recorder(hass)
await async_wait_recorder(hass)
instance = get_instance(hass)
instance._hass_started.cancel()
@ -240,7 +241,7 @@ async def test_state_gets_saved_when_set_before_start_event(
recorder_helper.async_initialize_recorder(hass)
hass.async_create_task(async_setup_recorder_instance(hass))
await recorder_helper.async_wait_recorder(hass)
await async_wait_recorder(hass)
entity_id = "test.recorder"
state = "restoring_from_db"
@ -2724,7 +2725,7 @@ async def test_commit_before_commits_pending_writes(
recorder_helper.async_initialize_recorder(hass)
hass.async_create_task(async_setup_recorder_instance(hass, config))
await recorder_helper.async_wait_recorder(hass)
await async_wait_recorder(hass)
instance = get_instance(hass)
assert instance.commit_interval == 60
verify_states_in_queue_future = hass.loop.create_future()

View File

@ -30,10 +30,9 @@ from homeassistant.components.recorder.db_schema import (
)
from homeassistant.components.recorder.util import session_scope
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers import recorder as recorder_helper
from homeassistant.util import dt as dt_util
from .common import async_wait_recording_done, create_engine_test
from .common import async_wait_recorder, async_wait_recording_done, create_engine_test
from .conftest import InstrumentedMigration
from tests.common import async_fire_time_changed
@ -641,7 +640,7 @@ async def test_schema_migrate(
)
await hass.async_add_executor_job(instrument_migration.migration_started.wait)
assert recorder.util.async_migration_in_progress(hass) is True
await recorder_helper.async_wait_recorder(hass)
await async_wait_recorder(hass)
assert recorder.util.async_migration_in_progress(hass) is True
assert recorder.util.async_migration_is_live(hass) == live

View File

@ -32,6 +32,7 @@ from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM
from .common import (
async_recorder_block_till_done,
async_wait_recorder,
async_wait_recording_done,
create_engine_test,
do_adhoc_statistics,
@ -2650,7 +2651,7 @@ async def test_recorder_info_migration_queue_exhausted(
instrument_migration.migration_started.wait
)
assert recorder.util.async_migration_in_progress(hass) is True
await recorder_helper.async_wait_recorder(hass)
await async_wait_recorder(hass)
hass.states.async_set("my.entity", "on", {})
await hass.async_block_till_done()

View File

@ -1557,7 +1557,7 @@ async def _async_init_recorder_component(
assert (recorder.DOMAIN in hass.config.components) == expected_setup_result
else:
# Wait for recorder to connect to the database
await recorder_helper.async_wait_recorder(hass)
await hass.data[recorder_helper.DOMAIN].db_connected
_LOGGER.info(
"Test recorder successfully started, database location: %s",
config[recorder.CONF_DB_URL],