mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00
Fix lutron_caseta get_triggers() raising error for non-button devices (caseta and ra3/hwqsx) (#78397)
This commit is contained in:
parent
74f7ae409b
commit
b51fd7f688
@ -405,7 +405,8 @@ async def async_get_triggers(
|
|||||||
triggers = []
|
triggers = []
|
||||||
|
|
||||||
if not (device := get_button_device_by_dr_id(hass, device_id)):
|
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(
|
valid_buttons = DEVICE_TYPE_SUBTYPE_MAP_TO_LEAP.get(
|
||||||
_lutron_model_to_device_type(device["model"], device["type"]), {}
|
_lutron_model_to_device_type(device["model"], device["type"]), {}
|
||||||
|
@ -5,9 +5,6 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant.components import automation
|
from homeassistant.components import automation
|
||||||
from homeassistant.components.device_automation import DeviceAutomationType
|
from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.components.device_automation.exceptions import (
|
|
||||||
InvalidDeviceAutomationConfig,
|
|
||||||
)
|
|
||||||
from homeassistant.components.lutron_caseta import (
|
from homeassistant.components.lutron_caseta import (
|
||||||
ATTR_ACTION,
|
ATTR_ACTION,
|
||||||
ATTR_AREA_NAME,
|
ATTR_AREA_NAME,
|
||||||
@ -140,6 +137,7 @@ async def test_get_triggers(hass, device_reg):
|
|||||||
triggers = await async_get_device_automations(
|
triggers = await async_get_device_automations(
|
||||||
hass, DeviceAutomationType.TRIGGER, device_id
|
hass, DeviceAutomationType.TRIGGER, device_id
|
||||||
)
|
)
|
||||||
|
|
||||||
assert_lists_same(triggers, expected_triggers)
|
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")},
|
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(InvalidDeviceAutomationConfig):
|
triggers = await async_get_device_automations(
|
||||||
await async_get_device_automations(
|
hass, DeviceAutomationType.TRIGGER, invalid_device.id
|
||||||
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):
|
async def test_if_fires_on_button_event(hass, calls, device_reg):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user