mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 05:47:10 +00:00
guard against invalid trigger and action scenarios (#32512)
This commit is contained in:
parent
ae0ea0f088
commit
b5022f5bcb
@ -56,7 +56,10 @@ async def async_call_action_from_config(
|
|||||||
|
|
||||||
async def async_get_actions(hass: HomeAssistant, device_id: str) -> List[dict]:
|
async def async_get_actions(hass: HomeAssistant, device_id: str) -> List[dict]:
|
||||||
"""List device actions."""
|
"""List device actions."""
|
||||||
zha_device = await async_get_zha_device(hass, device_id)
|
try:
|
||||||
|
zha_device = await async_get_zha_device(hass, device_id)
|
||||||
|
except (KeyError, AttributeError):
|
||||||
|
return []
|
||||||
cluster_channels = [
|
cluster_channels = [
|
||||||
ch.name
|
ch.name
|
||||||
for pool in zha_device.channels.pools
|
for pool in zha_device.channels.pools
|
||||||
@ -81,7 +84,10 @@ async def _execute_service_based_action(
|
|||||||
) -> None:
|
) -> None:
|
||||||
action_type = config[CONF_TYPE]
|
action_type = config[CONF_TYPE]
|
||||||
service_name = SERVICE_NAMES[action_type]
|
service_name = SERVICE_NAMES[action_type]
|
||||||
zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID])
|
try:
|
||||||
|
zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID])
|
||||||
|
except (KeyError, AttributeError):
|
||||||
|
return
|
||||||
|
|
||||||
service_data = {ATTR_IEEE: str(zha_device.ieee)}
|
service_data = {ATTR_IEEE: str(zha_device.ieee)}
|
||||||
|
|
||||||
|
@ -27,7 +27,10 @@ async def async_validate_trigger_config(hass, config):
|
|||||||
|
|
||||||
if "zha" in hass.config.components:
|
if "zha" in hass.config.components:
|
||||||
trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
|
trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
|
||||||
zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID])
|
try:
|
||||||
|
zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID])
|
||||||
|
except (KeyError, AttributeError):
|
||||||
|
raise InvalidDeviceAutomationConfig
|
||||||
if (
|
if (
|
||||||
zha_device.device_automation_triggers is None
|
zha_device.device_automation_triggers is None
|
||||||
or trigger not in zha_device.device_automation_triggers
|
or trigger not in zha_device.device_automation_triggers
|
||||||
@ -40,8 +43,10 @@ async def async_validate_trigger_config(hass, config):
|
|||||||
async def async_attach_trigger(hass, config, action, automation_info):
|
async def async_attach_trigger(hass, config, action, automation_info):
|
||||||
"""Listen for state changes based on configuration."""
|
"""Listen for state changes based on configuration."""
|
||||||
trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
|
trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
|
||||||
zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID])
|
try:
|
||||||
|
zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID])
|
||||||
|
except (KeyError, AttributeError):
|
||||||
|
return None
|
||||||
trigger = zha_device.device_automation_triggers[trigger]
|
trigger = zha_device.device_automation_triggers[trigger]
|
||||||
|
|
||||||
event_config = {
|
event_config = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user