Skip to content

Commit

Permalink
improve station class (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
mib1185 authored Jul 22, 2023
1 parent acddd3d commit 37054bb
Showing 1 changed file with 15 additions and 35 deletions.
50 changes: 15 additions & 35 deletions aiopegelonline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
from .exceptions import PegelonlineDataError


@dataclass
class Station:
"""Representation of a station."""

uuid: str
name: str
agency: str
river_kilometer: float | None
longitude: float | None
latitude: float | None
water_name: str
def __init__(self, data: dict) -> None:
"""Initialize station class."""
self.uuid: str = data["uuid"]
self.name: str = data["longname"]
self.agency: str = data["agency"]
self.river_kilometer: float | None = data.get("km")
self.longitude: float | None = data.get("longitude")
self.latitude: float | None = data.get("latitude")
self.water_name: str = data["water"]["longname"]
self.base_data_url: str = (
f"https://www.pegelonline.wsv.de/gast/stammdaten?pegelnr={data['number']}"
)


@dataclass
Expand Down Expand Up @@ -67,15 +71,7 @@ async def async_get_all_stations(self) -> dict[str, Station]:

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"],
)
result[station["uuid"]] = Station(station)

return result

Expand All @@ -95,15 +91,7 @@ async def async_get_nearby_stations(

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"],
)
result[station["uuid"]] = Station(station)

return result

Expand All @@ -113,15 +101,7 @@ async def async_get_station_details(self, uuid: str) -> Station:
f"{BASE_URL}/stations/{uuid}.json", {"prettyprint": "false"}
)

return Station(
station["uuid"],
station["longname"],
station["agency"],
station.get("km"),
station.get("longitude"),
station.get("latitude"),
station["water"]["longname"],
)
return Station(station)

async def async_get_station_measurement(self, uuid: str) -> CurrentMeasurement:
"""Get current measurement of a station."""
Expand Down

0 comments on commit 37054bb

Please sign in to comment.