mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Combine tts cache init executor jobs (#114271)
This commit is contained in:
parent
a6fabdc115
commit
1697b116e4
@ -507,24 +507,21 @@ class SpeechManager:
|
|||||||
self.file_cache: dict[str, str] = {}
|
self.file_cache: dict[str, str] = {}
|
||||||
self.mem_cache: dict[str, TTSCache] = {}
|
self.mem_cache: dict[str, TTSCache] = {}
|
||||||
|
|
||||||
async def async_init_cache(self) -> None:
|
def _init_cache(self) -> dict[str, str]:
|
||||||
"""Init config folder and load file cache."""
|
"""Init cache folder and fetch files."""
|
||||||
try:
|
try:
|
||||||
self.cache_dir = await self.hass.async_add_executor_job(
|
self.cache_dir = _init_tts_cache_dir(self.hass, self.cache_dir)
|
||||||
_init_tts_cache_dir, self.hass, self.cache_dir
|
|
||||||
)
|
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
raise HomeAssistantError(f"Can't init cache dir {err}") from err
|
raise HomeAssistantError(f"Can't init cache dir {err}") from err
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cache_files = await self.hass.async_add_executor_job(
|
return _get_cache_files(self.cache_dir)
|
||||||
_get_cache_files, self.cache_dir
|
|
||||||
)
|
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
raise HomeAssistantError(f"Can't read cache dir {err}") from err
|
raise HomeAssistantError(f"Can't read cache dir {err}") from err
|
||||||
|
|
||||||
if cache_files:
|
async def async_init_cache(self) -> None:
|
||||||
self.file_cache.update(cache_files)
|
"""Init config folder and load file cache."""
|
||||||
|
self.file_cache.update(await self.hass.async_add_executor_job(self._init_cache))
|
||||||
|
|
||||||
async def async_clear_cache(self) -> None:
|
async def async_clear_cache(self) -> None:
|
||||||
"""Read file cache and delete files."""
|
"""Read file cache and delete files."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user