* Add tts entity * Allow passing engine id to url view * Update async_resolve_engine * Add and update more tests * Fix assist pipeline tests temporarily * Move fixtures * Update notify platform * Complete legacy tests * Update media source tests * Update async_get_text_to_speech_languages * Address comment --------- Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
26 lines
753 B
Python
26 lines
753 B
Python
"""Provide helper functions for the TTS."""
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_component import EntityComponent
|
|
|
|
from .const import DATA_TTS_MANAGER, DOMAIN
|
|
|
|
if TYPE_CHECKING:
|
|
from . import SpeechManager, TextToSpeechEntity
|
|
from .legacy import Provider
|
|
|
|
|
|
def get_engine_instance(
|
|
hass: HomeAssistant, engine: str
|
|
) -> TextToSpeechEntity | Provider | None:
|
|
"""Get engine instance."""
|
|
component: EntityComponent[TextToSpeechEntity] = hass.data[DOMAIN]
|
|
|
|
if entity := component.get_entity(engine):
|
|
return entity
|
|
|
|
manager: SpeechManager = hass.data[DATA_TTS_MANAGER]
|
|
return manager.providers.get(engine)
|