mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove helper.recorder.async_wait_recorder (#138935)
This commit is contained in:
parent
b856de225d
commit
fb57284561
@ -60,16 +60,6 @@ def async_initialize_recorder(hass: HomeAssistant) -> None:
|
|||||||
async_setup(hass)
|
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)
|
@functools.lru_cache(maxsize=1)
|
||||||
def get_instance(hass: HomeAssistant) -> Recorder:
|
def get_instance(hass: HomeAssistant) -> Recorder:
|
||||||
"""Get the recorder instance."""
|
"""Get the recorder instance."""
|
||||||
|
@ -37,6 +37,7 @@ from homeassistant.components.recorder.db_schema import (
|
|||||||
from homeassistant.components.recorder.tasks import RecorderTask, StatisticsTask
|
from homeassistant.components.recorder.tasks import RecorderTask, StatisticsTask
|
||||||
from homeassistant.const import UnitOfTemperature
|
from homeassistant.const import UnitOfTemperature
|
||||||
from homeassistant.core import Event, HomeAssistant, State
|
from homeassistant.core import Event, HomeAssistant, State
|
||||||
|
from homeassistant.helpers import recorder as recorder_helper
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import db_schema_0
|
from . import db_schema_0
|
||||||
@ -79,6 +80,11 @@ async def async_block_recorder(hass: HomeAssistant, seconds: float) -> None:
|
|||||||
await event.wait()
|
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:
|
def get_start_time(start: datetime) -> datetime:
|
||||||
"""Calculate a valid start time for statistics."""
|
"""Calculate a valid start time for statistics."""
|
||||||
start_minutes = start.minute - start.minute % 5
|
start_minutes = start.minute - start.minute % 5
|
||||||
|
@ -85,6 +85,7 @@ from homeassistant.util.json import json_loads
|
|||||||
from .common import (
|
from .common import (
|
||||||
async_block_recorder,
|
async_block_recorder,
|
||||||
async_recorder_block_till_done,
|
async_recorder_block_till_done,
|
||||||
|
async_wait_recorder,
|
||||||
async_wait_recording_done,
|
async_wait_recording_done,
|
||||||
convert_pending_states_to_meta,
|
convert_pending_states_to_meta,
|
||||||
corrupt_db_file,
|
corrupt_db_file,
|
||||||
@ -155,7 +156,7 @@ async def test_shutdown_before_startup_finishes(
|
|||||||
|
|
||||||
recorder_helper.async_initialize_recorder(hass)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
hass.async_create_task(async_setup_recorder_instance(hass, config))
|
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)
|
instance = get_instance(hass)
|
||||||
|
|
||||||
session = await instance.async_add_executor_job(instance.get_session)
|
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)
|
hass.set_state(CoreState.not_running)
|
||||||
recorder_helper.async_initialize_recorder(hass)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
hass.async_create_task(async_setup_recorder_instance(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 = get_instance(hass)
|
||||||
instance._hass_started.cancel()
|
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)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
hass.async_create_task(async_setup_recorder_instance(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"
|
entity_id = "test.recorder"
|
||||||
state = "restoring_from_db"
|
state = "restoring_from_db"
|
||||||
@ -2724,7 +2725,7 @@ async def test_commit_before_commits_pending_writes(
|
|||||||
|
|
||||||
recorder_helper.async_initialize_recorder(hass)
|
recorder_helper.async_initialize_recorder(hass)
|
||||||
hass.async_create_task(async_setup_recorder_instance(hass, config))
|
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)
|
instance = get_instance(hass)
|
||||||
assert instance.commit_interval == 60
|
assert instance.commit_interval == 60
|
||||||
verify_states_in_queue_future = hass.loop.create_future()
|
verify_states_in_queue_future = hass.loop.create_future()
|
||||||
|
@ -30,10 +30,9 @@ from homeassistant.components.recorder.db_schema import (
|
|||||||
)
|
)
|
||||||
from homeassistant.components.recorder.util import session_scope
|
from homeassistant.components.recorder.util import session_scope
|
||||||
from homeassistant.core import HomeAssistant, State
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.helpers import recorder as recorder_helper
|
|
||||||
from homeassistant.util import dt as dt_util
|
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 .conftest import InstrumentedMigration
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
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)
|
await hass.async_add_executor_job(instrument_migration.migration_started.wait)
|
||||||
assert recorder.util.async_migration_in_progress(hass) is True
|
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_in_progress(hass) is True
|
||||||
assert recorder.util.async_migration_is_live(hass) == live
|
assert recorder.util.async_migration_is_live(hass) == live
|
||||||
|
@ -32,6 +32,7 @@ from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM
|
|||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
async_recorder_block_till_done,
|
async_recorder_block_till_done,
|
||||||
|
async_wait_recorder,
|
||||||
async_wait_recording_done,
|
async_wait_recording_done,
|
||||||
create_engine_test,
|
create_engine_test,
|
||||||
do_adhoc_statistics,
|
do_adhoc_statistics,
|
||||||
@ -2650,7 +2651,7 @@ async def test_recorder_info_migration_queue_exhausted(
|
|||||||
instrument_migration.migration_started.wait
|
instrument_migration.migration_started.wait
|
||||||
)
|
)
|
||||||
assert recorder.util.async_migration_in_progress(hass) is True
|
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", {})
|
hass.states.async_set("my.entity", "on", {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -1557,7 +1557,7 @@ async def _async_init_recorder_component(
|
|||||||
assert (recorder.DOMAIN in hass.config.components) == expected_setup_result
|
assert (recorder.DOMAIN in hass.config.components) == expected_setup_result
|
||||||
else:
|
else:
|
||||||
# Wait for recorder to connect to the database
|
# 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(
|
_LOGGER.info(
|
||||||
"Test recorder successfully started, database location: %s",
|
"Test recorder successfully started, database location: %s",
|
||||||
config[recorder.CONF_DB_URL],
|
config[recorder.CONF_DB_URL],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user