mirror of
https://github.com/home-assistant/core.git
synced 2025-07-07 13:27:09 +00:00
Add default_db_url flag to WS command recorder/info (#139333)
This commit is contained in:
parent
2bf592d8aa
commit
0c092f80c7
@ -149,9 +149,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
commit_interval = conf[CONF_COMMIT_INTERVAL]
|
||||
db_max_retries = conf[CONF_DB_MAX_RETRIES]
|
||||
db_retry_wait = conf[CONF_DB_RETRY_WAIT]
|
||||
db_url = conf.get(CONF_DB_URL) or DEFAULT_URL.format(
|
||||
hass_config_path=hass.config.path(DEFAULT_DB_FILE)
|
||||
)
|
||||
db_url = conf.get(CONF_DB_URL) or get_default_url(hass)
|
||||
exclude = conf[CONF_EXCLUDE]
|
||||
exclude_event_types: set[EventType[Any] | str] = set(
|
||||
exclude.get(CONF_EVENT_TYPES, [])
|
||||
@ -200,3 +198,8 @@ async def _async_setup_integration_platform(
|
||||
instance.queue_task(AddRecorderPlatformTask(domain, platform))
|
||||
|
||||
await async_process_integration_platforms(hass, DOMAIN, _process_recorder_platform)
|
||||
|
||||
|
||||
def get_default_url(hass: HomeAssistant) -> str:
|
||||
"""Return the default URL."""
|
||||
return DEFAULT_URL.format(hass_config_path=hass.config.path(DEFAULT_DB_FILE))
|
||||
|
@ -10,6 +10,7 @@ from homeassistant.components import websocket_api
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import recorder as recorder_helper
|
||||
|
||||
from . import get_default_url
|
||||
from .util import get_instance
|
||||
|
||||
|
||||
@ -34,6 +35,7 @@ async def ws_info(
|
||||
await hass.data[recorder_helper.DATA_RECORDER].db_connected
|
||||
instance = get_instance(hass)
|
||||
backlog = instance.backlog
|
||||
db_in_default_location = instance.db_url == get_default_url(hass)
|
||||
migration_in_progress = instance.migration_in_progress
|
||||
migration_is_live = instance.migration_is_live
|
||||
recording = instance.recording
|
||||
@ -44,6 +46,7 @@ async def ws_info(
|
||||
|
||||
recorder_info = {
|
||||
"backlog": backlog,
|
||||
"db_in_default_location": db_in_default_location,
|
||||
"max_backlog": max_backlog,
|
||||
"migration_in_progress": migration_in_progress,
|
||||
"migration_is_live": migration_is_live,
|
||||
|
@ -2562,6 +2562,7 @@ async def test_recorder_info(
|
||||
assert response["success"]
|
||||
assert response["result"] == {
|
||||
"backlog": 0,
|
||||
"db_in_default_location": False, # We never use the default URL in tests
|
||||
"max_backlog": 65000,
|
||||
"migration_in_progress": False,
|
||||
"migration_is_live": False,
|
||||
@ -2570,6 +2571,44 @@ async def test_recorder_info(
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("db_url", "db_in_default_location"),
|
||||
[
|
||||
("sqlite:///{config_dir}/home-assistant_v2.db", True),
|
||||
("sqlite:///{config_dir}/custom.db", False),
|
||||
("mysql://root:root_password@127.0.0.1:3316/homeassistant-test", False),
|
||||
],
|
||||
)
|
||||
async def test_recorder_info_default_url(
|
||||
recorder_mock: Recorder,
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
db_url: str,
|
||||
db_in_default_location: bool,
|
||||
) -> None:
|
||||
"""Test getting recorder status."""
|
||||
client = await hass_ws_client()
|
||||
|
||||
# Ensure there are no queued events
|
||||
await async_wait_recording_done(hass)
|
||||
|
||||
with patch.object(
|
||||
recorder_mock, "db_url", db_url.format(config_dir=hass.config.config_dir)
|
||||
):
|
||||
await client.send_json_auto_id({"type": "recorder/info"})
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
assert response["result"] == {
|
||||
"backlog": 0,
|
||||
"db_in_default_location": db_in_default_location,
|
||||
"max_backlog": 65000,
|
||||
"migration_in_progress": False,
|
||||
"migration_is_live": False,
|
||||
"recording": True,
|
||||
"thread_running": True,
|
||||
}
|
||||
|
||||
|
||||
async def test_recorder_info_no_recorder(
|
||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||
) -> None:
|
||||
@ -2624,6 +2663,7 @@ async def test_recorder_info_wait_database_connect(
|
||||
assert response["success"]
|
||||
assert response["result"] == {
|
||||
"backlog": ANY,
|
||||
"db_in_default_location": False,
|
||||
"max_backlog": 65000,
|
||||
"migration_in_progress": False,
|
||||
"migration_is_live": False,
|
||||
|
Loading…
x
Reference in New Issue
Block a user