From 61d96051078bc6ef84ee9c56fae108e87d73b534 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Fri, 21 Jul 2023 20:09:28 +0200 Subject: [PATCH] add async_get_nearby_stations() (#11) --- aiopegelonline/__init__.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/aiopegelonline/__init__.py b/aiopegelonline/__init__.py index d3a8377..5943dbb 100644 --- a/aiopegelonline/__init__.py +++ b/aiopegelonline/__init__.py @@ -79,6 +79,34 @@ async def async_get_all_stations(self) -> dict[str, Station]: return result + async def async_get_nearby_stations( + self, latitude: float, longitude: float, radius: int + ) -> dict[str, Station]: + """Get stations within defined radius at given position.""" + stations = await self._async_do_request( + f"{BASE_URL}/stations.json", + { + "prettyprint": "false", + "latitude": latitude, + "longitude": longitude, + "radius": radius, + }, + ) + + result = {} + for station in stations: + result[station["uuid"]] = Station( + station["uuid"], + station["longname"], + station["agency"], + station.get("km"), + station.get("longitude"), + station.get("latitude"), + station["water"]["longname"], + ) + + return result + async def async_get_station_details(self, uuid: str) -> Station: """Get station details.""" station = await self._async_do_request(