Fix lutron_caseta get_triggers() raising error for non-button devices (caseta and ra3/hwqsx) (#78397)

This commit is contained in:
Kevin Addeman 2022-09-17 14:26:04 -04:00 committed by GitHub
parent 74f7ae409b
commit b51fd7f688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -405,7 +405,8 @@ async def async_get_triggers(
triggers = []
if not (device := get_button_device_by_dr_id(hass, device_id)):
raise InvalidDeviceAutomationConfig(f"Device not found: {device_id}")
# Check if device is a valid button device. Return empty if not.
return []
valid_buttons = DEVICE_TYPE_SUBTYPE_MAP_TO_LEAP.get(
_lutron_model_to_device_type(device["model"], device["type"]), {}

View File

@ -5,9 +5,6 @@ import pytest
from homeassistant.components import automation
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.device_automation.exceptions import (
InvalidDeviceAutomationConfig,
)
from homeassistant.components.lutron_caseta import (
ATTR_ACTION,
ATTR_AREA_NAME,
@ -140,6 +137,7 @@ async def test_get_triggers(hass, device_reg):
triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_id
)
assert_lists_same(triggers, expected_triggers)
@ -152,10 +150,27 @@ async def test_get_triggers_for_invalid_device_id(hass, device_reg):
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
with pytest.raises(InvalidDeviceAutomationConfig):
await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, invalid_device.id
)
triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, invalid_device.id
)
assert triggers == []
async def test_get_triggers_for_non_button_device(hass, device_reg):
"""Test error raised for invalid lutron device_id."""
config_entry_id = await _async_setup_lutron_with_picos(hass, device_reg)
invalid_device = device_reg.async_get_or_create(
config_entry_id=config_entry_id,
identifiers={(DOMAIN, "invdevserial")},
)
triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, invalid_device.id
)
assert triggers == []
async def test_if_fires_on_button_event(hass, calls, device_reg):