Skip to content

Commit

Permalink
Merge pull request #32 from fcastilloec/async
Browse files Browse the repository at this point in the history
Use await async_forward_entry_setups for HA2025.1
  • Loading branch information
gdgib authored Jan 6, 2025
2 parents 385c45e + 6ca9e62 commit 96a58cd
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions custom_components/vesync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,23 @@ async def async_update_data():
hass.data[DOMAIN][config_entry.entry_id]["coordinator"] = coordinator

device_dict = await async_process_devices(hass, manager)
platforms_list: list = []

for p, vs_p in PLATFORMS.items():
for _, vs_p in PLATFORMS.items():
hass.data[DOMAIN][config_entry.entry_id][vs_p] = []
if device_dict[vs_p]:
hass.data[DOMAIN][config_entry.entry_id][vs_p].extend(device_dict[vs_p])
platforms_list.append(p)
await hass.config_entries.async_forward_entry_setups(config_entry, platforms_list)

await hass.config_entries.async_forward_entry_setups(
config_entry, list(PLATFORMS.keys())
)

async def async_new_device_discovery(service: ServiceCall) -> None:
"""Discover if new devices should be added."""
manager = hass.data[DOMAIN][config_entry.entry_id][VS_MANAGER]
dev_dict = await async_process_devices(hass, manager)
platforms_to_setup = []

def _add_new_devices(platform: str) -> None:
async def _add_new_devices(platform: str) -> None:
"""Add new devices to hass."""
old_devices = hass.data[DOMAIN][config_entry.entry_id][PLATFORMS[platform]]
if new_devices := list(
Expand All @@ -110,15 +112,16 @@ def _add_new_devices(platform: str) -> None:
hass, VS_DISCOVERY.format(PLATFORMS[platform]), new_devices
)
else:
hass.async_create_task(
hass.config_entries.async_forward_entry_setups(
config_entry, platform
)
)
platforms_to_setup.append(platform)

for k in PLATFORMS:
_add_new_devices(k)

if platforms_to_setup:
await hass.config_entries.async_forward_entry_setups(
config_entry, platforms_to_setup
)

hass.services.async_register(
DOMAIN, SERVICE_UPDATE_DEVS, async_new_device_discovery
)
Expand Down

0 comments on commit 96a58cd

Please sign in to comment.