From b65b47f25ee9b44501f9865300628043eb004948 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 19 May 2022 17:05:25 +0200 Subject: [PATCH] Cleanup zha async method which is not awaiting (#72093) * Cleanup zha async method which is not awaiting * Missed a commit --- homeassistant/components/zha/core/helpers.py | 3 ++- homeassistant/components/zha/device_action.py | 4 ++-- homeassistant/components/zha/device_trigger.py | 6 +++--- homeassistant/components/zha/diagnostics.py | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/zha/core/helpers.py b/homeassistant/components/zha/core/helpers.py index 19a1d3fef9a..a101720e8df 100644 --- a/homeassistant/components/zha/core/helpers.py +++ b/homeassistant/components/zha/core/helpers.py @@ -160,7 +160,8 @@ def async_cluster_exists(hass, cluster_id): return False -async def async_get_zha_device(hass, device_id): +@callback +def async_get_zha_device(hass, device_id): """Get a ZHA device for the given device registry id.""" device_registry = dr.async_get(hass) registry_device = device_registry.async_get(device_id) diff --git a/homeassistant/components/zha/device_action.py b/homeassistant/components/zha/device_action.py index 36696517eb6..f941b559cc7 100644 --- a/homeassistant/components/zha/device_action.py +++ b/homeassistant/components/zha/device_action.py @@ -61,7 +61,7 @@ async def async_get_actions( ) -> list[dict[str, str]]: """List device actions.""" try: - zha_device = await async_get_zha_device(hass, device_id) + zha_device = async_get_zha_device(hass, device_id) except (KeyError, AttributeError): return [] cluster_channels = [ @@ -89,7 +89,7 @@ async def _execute_service_based_action( action_type = config[CONF_TYPE] service_name = SERVICE_NAMES[action_type] try: - zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID]) + zha_device = async_get_zha_device(hass, config[CONF_DEVICE_ID]) except (KeyError, AttributeError): return diff --git a/homeassistant/components/zha/device_trigger.py b/homeassistant/components/zha/device_trigger.py index 03bdc32e6a6..d81d8164bd4 100644 --- a/homeassistant/components/zha/device_trigger.py +++ b/homeassistant/components/zha/device_trigger.py @@ -28,7 +28,7 @@ async def async_validate_trigger_config(hass, config): if "zha" in hass.config.components: trigger = (config[CONF_TYPE], config[CONF_SUBTYPE]) try: - zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID]) + zha_device = async_get_zha_device(hass, config[CONF_DEVICE_ID]) except (KeyError, AttributeError) as err: raise InvalidDeviceAutomationConfig from err if ( @@ -44,7 +44,7 @@ async def async_attach_trigger(hass, config, action, automation_info): """Listen for state changes based on configuration.""" trigger = (config[CONF_TYPE], config[CONF_SUBTYPE]) try: - zha_device = await async_get_zha_device(hass, config[CONF_DEVICE_ID]) + zha_device = async_get_zha_device(hass, config[CONF_DEVICE_ID]) except (KeyError, AttributeError): return None @@ -71,7 +71,7 @@ async def async_get_triggers(hass, device_id): Make sure the device supports device automations and if it does return the trigger list. """ - zha_device = await async_get_zha_device(hass, device_id) + zha_device = async_get_zha_device(hass, device_id) if not zha_device.device_automation_triggers: return diff --git a/homeassistant/components/zha/diagnostics.py b/homeassistant/components/zha/diagnostics.py index ec8dab241de..5ae2ff23e96 100644 --- a/homeassistant/components/zha/diagnostics.py +++ b/homeassistant/components/zha/diagnostics.py @@ -76,5 +76,5 @@ async def async_get_device_diagnostics( hass: HomeAssistant, config_entry: ConfigEntry, device: dr.DeviceEntry ) -> dict: """Return diagnostics for a device.""" - zha_device: ZHADevice = await async_get_zha_device(hass, device.id) + zha_device: ZHADevice = async_get_zha_device(hass, device.id) return async_redact_data(zha_device.zha_device_info, KEYS_TO_REDACT)