1 """Support notifications through TTS service."""
3 from __future__
import annotations
8 import voluptuous
as vol
11 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
12 BaseNotificationService,
19 from .
import ATTR_LANGUAGE, ATTR_MEDIA_PLAYER_ENTITY_ID, ATTR_MESSAGE, DOMAIN
21 CONF_MEDIA_PLAYER =
"media_player"
22 CONF_TTS_SERVICE =
"tts_service"
23 ENTITY_LEGACY_PROVIDER_GROUP =
"entity_or_legacy_provider"
25 _LOGGER = logging.getLogger(__name__)
27 PLATFORM_SCHEMA = vol.All(
28 cv.has_at_least_one_key(CONF_TTS_SERVICE, CONF_ENTITY_ID),
29 NOTIFY_PLATFORM_SCHEMA.extend(
31 vol.Required(CONF_NAME): cv.string,
32 vol.Exclusive(CONF_TTS_SERVICE, ENTITY_LEGACY_PROVIDER_GROUP): cv.entity_id,
34 CONF_ENTITY_ID, ENTITY_LEGACY_PROVIDER_GROUP
35 ): cv.entities_domain(DOMAIN),
36 vol.Required(CONF_MEDIA_PLAYER): cv.entity_id,
37 vol.Optional(ATTR_LANGUAGE): cv.string,
46 discovery_info: DiscoveryInfoType |
None =
None,
47 ) -> TTSNotificationService:
48 """Return the notify service."""
54 """The TTS Notification Service."""
56 def __init__(self, config: ConfigType) ->
None:
57 """Initialize the service."""
58 self.
_target_target: str |
None =
None
60 if entity_id := config.get(CONF_ENTITY_ID):
68 """Call TTS service to speak the notification."""
72 ATTR_MESSAGE: message,
80 data[ATTR_ENTITY_ID] = self.
_target_target
81 data[ATTR_MEDIA_PLAYER_ENTITY_ID] = self.
_media_player_media_player
82 service_name =
"speak"
84 data[ATTR_LANGUAGE] = self.
_language_language
86 await self.hass.services.async_call(
None async_send_message(self, str message="", **Any kwargs)
None __init__(self, ConfigType config)
TTSNotificationService async_get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)
tuple[str, str] split_entity_id(str entity_id)