Fix tts notify config validation (#98381)
* Add test * Require either entity_id or tts_service
This commit is contained in:
parent
57cacbc2a7
commit
6f97270cd2
2 changed files with 28 additions and 10 deletions
|
@ -20,16 +20,19 @@ ENTITY_LEGACY_PROVIDER_GROUP = "entity_or_legacy_provider"
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_NAME): cv.string,
|
||||
vol.Exclusive(CONF_TTS_SERVICE, ENTITY_LEGACY_PROVIDER_GROUP): cv.entity_id,
|
||||
vol.Exclusive(CONF_ENTITY_ID, ENTITY_LEGACY_PROVIDER_GROUP): cv.entities_domain(
|
||||
DOMAIN
|
||||
),
|
||||
vol.Required(CONF_MEDIA_PLAYER): cv.entity_id,
|
||||
vol.Optional(ATTR_LANGUAGE): cv.string,
|
||||
}
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
cv.has_at_least_one_key(CONF_TTS_SERVICE, CONF_ENTITY_ID),
|
||||
PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_NAME): cv.string,
|
||||
vol.Exclusive(CONF_TTS_SERVICE, ENTITY_LEGACY_PROVIDER_GROUP): cv.entity_id,
|
||||
vol.Exclusive(
|
||||
CONF_ENTITY_ID, ENTITY_LEGACY_PROVIDER_GROUP
|
||||
): cv.entities_domain(DOMAIN),
|
||||
vol.Required(CONF_MEDIA_PLAYER): cv.entity_id,
|
||||
vol.Optional(ATTR_LANGUAGE): cv.string,
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -68,6 +68,21 @@ async def test_setup_platform(hass: HomeAssistant) -> None:
|
|||
assert hass.services.has_service(notify.DOMAIN, "tts_test")
|
||||
|
||||
|
||||
async def test_setup_platform_missing_key(hass: HomeAssistant) -> None:
|
||||
"""Test platform without required tts_service or entity_id key."""
|
||||
config = {
|
||||
notify.DOMAIN: {
|
||||
"platform": "tts",
|
||||
"name": "tts_test",
|
||||
"media_player": "media_player.demo",
|
||||
}
|
||||
}
|
||||
with assert_setup_component(0, notify.DOMAIN):
|
||||
assert await async_setup_component(hass, notify.DOMAIN, config)
|
||||
|
||||
assert not hass.services.has_service(notify.DOMAIN, "tts_test")
|
||||
|
||||
|
||||
async def test_setup_legacy_service(hass: HomeAssistant) -> None:
|
||||
"""Set up the demo platform and call service."""
|
||||
calls = async_mock_service(hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||
|
|
Loading…
Add table
Reference in a new issue