Extract the storage layer into core
This commit is contained in:
@@ -1,20 +1,29 @@
|
||||
"""SQLite storage path resolution for the NestQuest integration."""
|
||||
"""Re-export of :mod:`core.store` for the integration package.
|
||||
|
||||
The path resolver lives in :mod:`core.store` (extracted in task
|
||||
d0b691d8) and is Home-Assistant-free: :func:`core.store.async_get_db_path`
|
||||
takes the full database path. This module re-exports it and provides
|
||||
the original ``async_get_db_path(hass)`` signature so the integration
|
||||
resolves the path from ``hass.config.path`` exactly as before.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import SQLITE_DB_FILENAME
|
||||
from core.const import SQLITE_DB_FILENAME
|
||||
from core.store import async_get_db_path as _core_async_get_db_path
|
||||
from core.store import _ensure_dir
|
||||
|
||||
|
||||
def _ensure_dir(path: Path) -> None:
|
||||
"""Create the given directory and any missing parents."""
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
__all__ = ["async_get_db_path", "_ensure_dir"]
|
||||
|
||||
|
||||
async def async_get_db_path(hass: HomeAssistant) -> Path:
|
||||
"""Return the absolute path to the NestQuest SQLite database file."""
|
||||
db_path = Path(hass.config.path(SQLITE_DB_FILENAME)).absolute()
|
||||
await hass.async_add_executor_job(_ensure_dir, db_path.parent)
|
||||
return db_path
|
||||
"""Return the absolute path to the NestQuest SQLite database file.
|
||||
|
||||
Resolves the database file from ``hass.config.path`` and delegates to
|
||||
:func:`core.store.async_get_db_path`, which ensures the parent
|
||||
directory exists off the event loop via :func:`asyncio.to_thread`.
|
||||
"""
|
||||
return await _core_async_get_db_path(hass.config.path(SQLITE_DB_FILENAME))
|
||||
|
||||
Reference in New Issue
Block a user