2023-04-21 02:55:46 +00:00
|
|
|
"""Provide helper functions for the TTS."""
|
2024-03-08 15:35:23 +00:00
|
|
|
|
2023-04-21 02:55:46 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
2024-09-25 13:53:58 +00:00
|
|
|
from .const import DATA_COMPONENT, DATA_TTS_MANAGER
|
2023-04-21 02:55:46 +00:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
2024-09-21 11:14:27 +00:00
|
|
|
from . import TextToSpeechEntity
|
2023-04-21 02:55:46 +00:00
|
|
|
from .legacy import Provider
|
|
|
|
|
|
|
|
|
|
|
|
def get_engine_instance(
|
|
|
|
hass: HomeAssistant, engine: str
|
|
|
|
) -> TextToSpeechEntity | Provider | None:
|
|
|
|
"""Get engine instance."""
|
2024-09-25 13:53:58 +00:00
|
|
|
if entity := hass.data[DATA_COMPONENT].get_entity(engine):
|
2023-04-21 02:55:46 +00:00
|
|
|
return entity
|
|
|
|
|
2024-09-21 11:14:27 +00:00
|
|
|
return hass.data[DATA_TTS_MANAGER].providers.get(engine)
|