Better handle invalid trigger config (#55637)
This commit is contained in:
parent
e0f640c0f8
commit
7111fc47c4
4 changed files with 37 additions and 19 deletions
|
@ -7,6 +7,8 @@ from homeassistant.components.device_automation import (
|
|||
)
|
||||
from homeassistant.const import CONF_DOMAIN
|
||||
|
||||
from .exceptions import InvalidDeviceAutomationConfig
|
||||
|
||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
||||
|
||||
TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend({}, extra=vol.ALLOW_EXTRA)
|
||||
|
@ -17,10 +19,13 @@ async def async_validate_trigger_config(hass, config):
|
|||
platform = await async_get_device_automation_platform(
|
||||
hass, config[CONF_DOMAIN], "trigger"
|
||||
)
|
||||
if hasattr(platform, "async_validate_trigger_config"):
|
||||
return await getattr(platform, "async_validate_trigger_config")(hass, config)
|
||||
if not hasattr(platform, "async_validate_trigger_config"):
|
||||
return platform.TRIGGER_SCHEMA(config)
|
||||
|
||||
return platform.TRIGGER_SCHEMA(config)
|
||||
try:
|
||||
return await getattr(platform, "async_validate_trigger_config")(hass, config)
|
||||
except InvalidDeviceAutomationConfig as err:
|
||||
raise vol.Invalid(str(err) or "Invalid trigger configuration") from err
|
||||
|
||||
|
||||
async def async_attach_trigger(hass, config, action, automation_info):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue