Guard for unexpected exceptions in device automation (#55639)
* Guard for unexpected exceptions in device automation * merge Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
a234f2ab31
commit
418d6a6a41
2 changed files with 32 additions and 1 deletions
|
@ -1,4 +1,6 @@
|
|||
"""The test for light device automation."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import device_automation
|
||||
|
@ -443,6 +445,28 @@ async def test_async_get_device_automations_all_devices_action(
|
|||
assert len(result[device_entry.id]) == 3
|
||||
|
||||
|
||||
async def test_async_get_device_automations_all_devices_action_exception_throw(
|
||||
hass, device_reg, entity_reg, caplog
|
||||
):
|
||||
"""Test we get can fetch all the actions when no device id is passed and can handle one throwing an exception."""
|
||||
await async_setup_component(hass, "device_automation", {})
|
||||
config_entry = MockConfigEntry(domain="test", data={})
|
||||
config_entry.add_to_hass(hass)
|
||||
device_entry = device_reg.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
|
||||
with patch(
|
||||
"homeassistant.components.light.device_trigger.async_get_triggers",
|
||||
side_effect=KeyError,
|
||||
):
|
||||
result = await device_automation.async_get_device_automations(hass, "trigger")
|
||||
assert device_entry.id in result
|
||||
assert len(result[device_entry.id]) == 0
|
||||
assert "KeyError" in caplog.text
|
||||
|
||||
|
||||
async def test_websocket_get_trigger_capabilities(
|
||||
hass, hass_ws_client, device_reg, entity_reg
|
||||
):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue