Combine tts cache init executor jobs (#114271)

This commit is contained in:
J. Nick Koston 2024-03-26 17:58:46 -10:00 committed by GitHub
parent a6fabdc115
commit 1697b116e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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."""