Skip to content

Commit

Permalink
at init: Replace deprecated async entry setup call with suggestion.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
estebanz01 committed Jul 5, 2024
1 parent d2fa4dc commit 79c561c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions custom_components/localtuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _device_discovered(device):
)
new_data[ATTR_UPDATED_AT] = str(int(time.time() * 1000))
hass.config_entries.async_update_entry(entry, data=new_data)

elif device_id in hass.data[DOMAIN][TUYA_DEVICES]:
_LOGGER.debug("Device %s found with IP %s", device_id, device_ip)

Expand Down Expand Up @@ -270,12 +270,9 @@ async def setup_entities(device_ids):
)
hass.data[DOMAIN][TUYA_DEVICES][dev_id] = TuyaDevice(hass, entry, dev_id)

await asyncio.gather(
*[
hass.config_entries.async_forward_entry_setup(entry, platform)
for platform in platforms
]
)
# 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()
Expand Down

0 comments on commit 79c561c

Please sign in to comment.