diff --git a/example.py b/example.py index 71d862c..0315dde 100644 --- a/example.py +++ b/example.py @@ -36,6 +36,6 @@ async def main() -> None: print(data) -loop = asyncio.get_event_loop() +loop = asyncio.new_event_loop() loop.run_until_complete(main()) loop.close() diff --git a/gios/__init__.py b/gios/__init__.py index 1d733ee..0146503 100644 --- a/gios/__init__.py +++ b/gios/__init__.py @@ -1,5 +1,6 @@ """Python wrapper for getting air quality data from GIOS.""" +import asyncio import logging from contextlib import suppress from http import HTTPStatus @@ -131,11 +132,10 @@ async def _get_station(self) -> Any: async def _get_all_sensors(self, sensors: dict[str, Any]) -> dict[str, Any]: """Retrieve all sensors data.""" - data: dict[str, Any] = {} - for sensor in sensors: - sensor_data = await self._get_sensor(sensors[sensor][ATTR_ID]) - data[sensor] = sensor_data - return data + results = await asyncio.gather( + *[self._get_sensor(sensors[sensor][ATTR_ID]) for sensor in sensors] + ) + return dict(zip(sensors, results, strict=True)) async def _get_sensor(self, sensor: int) -> Any: """Retrieve sensor data."""