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:
committed by
rospogrigio
parent
e6bcaa1127
commit
2217b09286
@@ -263,19 +263,19 @@ 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
|
||||||
|
|
||||||
|
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):
|
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:
|
for dev_id in device_ids:
|
||||||
hass.data[DOMAIN][TUYA_DEVICES][dev_id].async_connect()
|
hass.data[DOMAIN][TUYA_DEVICES][dev_id].async_connect()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user