From 2217b09286c3cfbb010bb15ac7c5bc8ed0e6c5e6 Mon Sep 17 00:00:00 2001 From: Michiel De Wilde Date: Tue, 22 Apr 2025 18:13:46 +0200 Subject: [PATCH] Deprecation fix: do not call async_forward_entry_setups in an async task This fixes the following reported issue: Detected that custom integration 'localtuya' calls async_forward_entry_setups for integration localtuya with title: *** and entry_id: ***, during setup without awaiting async_forward_entry_setups, which can cause the setup lock to be released before the setup is done at custom_components/localtuya/__init__.py, line 275: await hass.config_entries.async_forward_entry_setups(entry, platforms). This will stop working in Home Assistant 2025.1, please create a bug report at https://github.com/rospogrigio/localtuya/issues --- custom_components/localtuya/__init__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index 2f0e0fc..a54656d 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -263,19 +263,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): res = await tuya_api.async_get_devices_list() hass.data[DOMAIN][DATA_CLOUD] = tuya_api + platforms = set() + for dev_id in entry.data[CONF_DEVICES].keys(): + entities = entry.data[CONF_DEVICES][dev_id][CONF_ENTITIES] + platforms = platforms.union( + set(entity[CONF_PLATFORM] for entity in entities) + ) + hass.data[DOMAIN][TUYA_DEVICES][dev_id] = TuyaDevice(hass, entry, dev_id) + + # Setup all platforms at once, letting HA handling each platform and avoiding + # potential integration restarts while elements are still initialising. + await hass.config_entries.async_forward_entry_setups(entry, platforms) + async def setup_entities(device_ids): - platforms = set() - for dev_id in device_ids: - entities = entry.data[CONF_DEVICES][dev_id][CONF_ENTITIES] - platforms = platforms.union( - set(entity[CONF_PLATFORM] for entity in entities) - ) - hass.data[DOMAIN][TUYA_DEVICES][dev_id] = TuyaDevice(hass, entry, dev_id) - - # Setup all platforms at once, letting HA handling each platform and avoiding - # potential integration restarts while elements are still initialising. - await hass.config_entries.async_forward_entry_setups(entry, platforms) - for dev_id in device_ids: hass.data[DOMAIN][TUYA_DEVICES][dev_id].async_connect()