Skip to content

Commit

Permalink
add async_get_nearby_stations() (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mib1185 authored Jul 21, 2023
1 parent 2fcf160 commit 61d9605
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions aiopegelonline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 61d9605

Please sign in to comment.