Skip to content

Commit a558e12

Browse files
committed
feat: Gather tasks
1 parent 364e88e commit a558e12

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

roborock/devices/device_manager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Module for discovering Roborock devices."""
22

3+
import asyncio
34
import logging
45
from collections.abc import Awaitable, Callable
56

@@ -56,6 +57,7 @@ async def discover_devices(self) -> list[RoborockDevice]:
5657
device_products = home_data.device_products
5758
_LOGGER.debug("Discovered %d devices %s", len(device_products), home_data)
5859

60+
# These are connected serially to avoid overwhelming the MQTT broker
5961
new_devices = {}
6062
for duid, (device, product) in device_products.items():
6163
if duid in self._devices:
@@ -77,11 +79,10 @@ async def get_devices(self) -> list[RoborockDevice]:
7779

7880
async def close(self) -> None:
7981
"""Close all MQTT connections and clean up resources."""
80-
for device in self._devices.values():
81-
await device.close()
82+
tasks = [device.close() for device in self._devices.values()]
8283
self._devices.clear()
83-
if self._mqtt_session:
84-
await self._mqtt_session.close()
84+
tasks.append(self._mqtt_session.close())
85+
await asyncio.gather(*tasks)
8586

8687

8788
def create_home_data_api(email: str, user_data: UserData) -> HomeDataApi:

0 commit comments

Comments
 (0)