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
This commit is contained in:
Michiel De Wilde
2025-04-22 18:13:46 +02:00
committed by rospogrigio
parent e6bcaa1127
commit 2217b09286

View File

@@ -263,9 +263,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
res = await tuya_api.async_get_devices_list() res = await tuya_api.async_get_devices_list()
hass.data[DOMAIN][DATA_CLOUD] = tuya_api hass.data[DOMAIN][DATA_CLOUD] = tuya_api
async def setup_entities(device_ids):
platforms = set() platforms = set()
for dev_id in device_ids: for dev_id in entry.data[CONF_DEVICES].keys():
entities = entry.data[CONF_DEVICES][dev_id][CONF_ENTITIES] entities = entry.data[CONF_DEVICES][dev_id][CONF_ENTITIES]
platforms = platforms.union( platforms = platforms.union(
set(entity[CONF_PLATFORM] for entity in entities) set(entity[CONF_PLATFORM] for entity in entities)
@@ -276,6 +275,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
# potential integration restarts while elements are still initialising. # potential integration restarts while elements are still initialising.
await hass.config_entries.async_forward_entry_setups(entry, platforms) await hass.config_entries.async_forward_entry_setups(entry, platforms)
async def setup_entities(device_ids):
for dev_id in device_ids: for dev_id in device_ids:
hass.data[DOMAIN][TUYA_DEVICES][dev_id].async_connect() hass.data[DOMAIN][TUYA_DEVICES][dev_id].async_connect()