diff --git a/homeassistant/components/zha/device_action.py b/homeassistant/components/zha/device_action.py index 5a2e0c40881..46363939190 100644 --- a/homeassistant/components/zha/device_action.py +++ b/homeassistant/components/zha/device_action.py @@ -56,7 +56,10 @@ async def async_call_action_from_config( async def async_get_actions(hass: HomeAssistant, device_id: str) -> List[dict]: """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 = [ ch.name for pool in zha_device.channels.pools @@ -81,7 +84,10 @@ async def _execute_service_based_action( ) -> None: action_type = config[CONF_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)} diff --git a/homeassistant/components/zha/device_trigger.py b/homeassistant/components/zha/device_trigger.py index b7c46e5a40a..222fdfc7a2c 100644 --- a/homeassistant/components/zha/device_trigger.py +++ b/homeassistant/components/zha/device_trigger.py @@ -27,7 +27,10 @@ async def async_validate_trigger_config(hass, config): if "zha" in hass.config.components: 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 ( zha_device.device_automation_triggers is None 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): """Listen for state changes based on configuration.""" 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] event_config = {