Fix asyncio.gather call (#107500)

This commit is contained in:
Marc Mueller 2024-01-08 09:35:47 +01:00 committed by GitHub
parent 3709475cb5
commit 442eb68d92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,8 +2,10 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
from collections.abc import Coroutine
import json import json
import logging import logging
from typing import Any
import aiohttp import aiohttp
from aiohttp.hdrs import CONTENT_TYPE from aiohttp.hdrs import CONTENT_TYPE
@ -267,11 +269,11 @@ class MicrosoftFace:
"""Store group/person data and IDs.""" """Store group/person data and IDs."""
return self._store return self._store
async def update_store(self): async def update_store(self) -> None:
"""Load all group/person data into local store.""" """Load all group/person data into local store."""
groups = await self.call_api("get", "persongroups") groups = await self.call_api("get", "persongroups")
remove_tasks = [] remove_tasks: list[Coroutine[Any, Any, None]] = []
new_entities = [] new_entities = []
for group in groups: for group in groups:
g_id = group["personGroupId"] g_id = group["personGroupId"]
@ -293,7 +295,7 @@ class MicrosoftFace:
self._store[g_id][person["name"]] = person["personId"] self._store[g_id][person["name"]] = person["personId"]
if remove_tasks: if remove_tasks:
await asyncio.gather(remove_tasks) await asyncio.gather(*remove_tasks)
await self._component.async_add_entities(new_entities) await self._component.async_add_entities(new_entities)
async def call_api(self, method, function, data=None, binary=False, params=None): async def call_api(self, method, function, data=None, binary=False, params=None):