mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Fix tts notify config validation (#98381)
* Add test * Require either entity_id or tts_service
This commit is contained in:
parent
57cacbc2a7
commit
6f97270cd2
@ -20,16 +20,19 @@ ENTITY_LEGACY_PROVIDER_GROUP = "entity_or_legacy_provider"
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = vol.All(
|
||||||
{
|
cv.has_at_least_one_key(CONF_TTS_SERVICE, CONF_ENTITY_ID),
|
||||||
vol.Required(CONF_NAME): cv.string,
|
PLATFORM_SCHEMA.extend(
|
||||||
vol.Exclusive(CONF_TTS_SERVICE, ENTITY_LEGACY_PROVIDER_GROUP): cv.entity_id,
|
{
|
||||||
vol.Exclusive(CONF_ENTITY_ID, ENTITY_LEGACY_PROVIDER_GROUP): cv.entities_domain(
|
vol.Required(CONF_NAME): cv.string,
|
||||||
DOMAIN
|
vol.Exclusive(CONF_TTS_SERVICE, ENTITY_LEGACY_PROVIDER_GROUP): cv.entity_id,
|
||||||
),
|
vol.Exclusive(
|
||||||
vol.Required(CONF_MEDIA_PLAYER): cv.entity_id,
|
CONF_ENTITY_ID, ENTITY_LEGACY_PROVIDER_GROUP
|
||||||
vol.Optional(ATTR_LANGUAGE): cv.string,
|
): 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")
|
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:
|
async def test_setup_legacy_service(hass: HomeAssistant) -> None:
|
||||||
"""Set up the demo platform and call service."""
|
"""Set up the demo platform and call service."""
|
||||||
calls = async_mock_service(hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
calls = async_mock_service(hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user