mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Handle empty service in script action gracefully (#27467)
* Handle empty service in script action gracefully * Add test
This commit is contained in:
parent
ee8b72fb71
commit
42691b783e
@ -386,6 +386,7 @@ def remove_falsy(value: List[T]) -> List[T]:
|
|||||||
def service(value):
|
def service(value):
|
||||||
"""Validate service."""
|
"""Validate service."""
|
||||||
# Services use same format as entities so we can use same helper.
|
# Services use same format as entities so we can use same helper.
|
||||||
|
value = string(value).lower()
|
||||||
if valid_entity_id(value):
|
if valid_entity_id(value):
|
||||||
return value
|
return value
|
||||||
raise vol.Invalid("Service {} does not match format <domain>.<name>".format(value))
|
raise vol.Invalid("Service {} does not match format <domain>.<name>".format(value))
|
||||||
|
@ -842,6 +842,25 @@ async def test_automation_with_error_in_script(hass, caplog):
|
|||||||
assert "Service not found" in caplog.text
|
assert "Service not found" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
async def test_automation_with_error_in_script_2(hass, caplog):
|
||||||
|
"""Test automation with an error in script."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
automation.DOMAIN,
|
||||||
|
{
|
||||||
|
automation.DOMAIN: {
|
||||||
|
"alias": "hello",
|
||||||
|
"trigger": {"platform": "event", "event_type": "test_event"},
|
||||||
|
"action": {"service": None, "entity_id": "hello.world"},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
hass.bus.async_fire("test_event")
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert "string value is None" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_automation_restore_last_triggered_with_initial_state(hass):
|
async def test_automation_restore_last_triggered_with_initial_state(hass):
|
||||||
"""Ensure last_triggered is restored, even when initial state is set."""
|
"""Ensure last_triggered is restored, even when initial state is set."""
|
||||||
time = dt_util.utcnow()
|
time = dt_util.utcnow()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user