at init: Replace deprecated async entry setup call with suggestion.
Based on https://developers.home-assistant.io/blog/2024/06/12/async_forward_entry_setups/ it is possible to replace it with `async_forward_entry_setups` instead, which accepts multiple platforms and it should be more efficient.
This commit is contained in:
committed by
rospogrigio
parent
d2fa4dc2a0
commit
87d61eea6f
@@ -139,7 +139,7 @@ async def async_setup(hass: HomeAssistant, config: dict):
|
|||||||
)
|
)
|
||||||
new_data[ATTR_UPDATED_AT] = str(int(time.time() * 1000))
|
new_data[ATTR_UPDATED_AT] = str(int(time.time() * 1000))
|
||||||
hass.config_entries.async_update_entry(entry, data=new_data)
|
hass.config_entries.async_update_entry(entry, data=new_data)
|
||||||
|
|
||||||
elif device_id in hass.data[DOMAIN][TUYA_DEVICES]:
|
elif device_id in hass.data[DOMAIN][TUYA_DEVICES]:
|
||||||
_LOGGER.debug("Device %s found with IP %s", device_id, device_ip)
|
_LOGGER.debug("Device %s found with IP %s", device_id, device_ip)
|
||||||
|
|
||||||
@@ -270,12 +270,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
)
|
)
|
||||||
hass.data[DOMAIN][TUYA_DEVICES][dev_id] = TuyaDevice(hass, entry, dev_id)
|
hass.data[DOMAIN][TUYA_DEVICES][dev_id] = TuyaDevice(hass, entry, dev_id)
|
||||||
|
|
||||||
await asyncio.gather(
|
# Setup all platforms at once, letting HA handling each platform and avoiding
|
||||||
*[
|
# potential integration restarts while elements are still initialising.
|
||||||
hass.config_entries.async_forward_entry_setup(entry, platform)
|
await hass.config_entries.async_forward_entry_setups(entry, platforms)
|
||||||
for platform in 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