Skip to content

Commit

Permalink
interface: add raw API data
Browse files Browse the repository at this point in the history
  • Loading branch information
Noltari authored Aug 23, 2023
1 parent 975dc02 commit cfe51cb
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions aemet_opendata/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
API_URL,
ATTR_DATA,
ATTR_RESPONSE,
RAW_STATION,
RAW_TOWN,
RAW_FORECAST_DAILY,
RAW_FORECAST_HOURLY,
RAW_STATIONS,
RAW_TOWNS,
)
from .exceptions import (
AemetError,
Expand Down Expand Up @@ -61,6 +63,12 @@ def __init__(
options: ConnectionOptions,
) -> None:
"""Init AEMET OpenData API."""
self._api_raw_data: dict[str, Any] = {
RAW_FORECAST_DAILY: {},
RAW_FORECAST_HOURLY: {},
RAW_STATIONS: {},
RAW_TOWNS: {},
}
self.aiohttp_session = aiohttp_session
self.coords: tuple[float, float] | None = None
self.dist_hp: bool = False
Expand Down Expand Up @@ -134,12 +142,7 @@ async def api_data(self, url: str) -> dict[str, Any]:

def raw_data(self) -> dict[str, Any]:
"""Return raw AEMET OpenData API data."""
data: dict[str, Any] = {}
if self.station is not None:
data[RAW_STATION] = self.station.raw_data()
if self.town is not None:
data[RAW_TOWN] = self.town.raw_data()
return data
return self._api_raw_data

def data(self) -> dict[str, Any]:
"""Return AEMET OpenData data."""
Expand Down Expand Up @@ -255,9 +258,11 @@ async def get_conventional_observation_station_data(
self, station: str, fetch_data: bool = True
) -> dict[str, Any]:
"""Get data from conventional observation station."""
return await self.api_call(
res await self.api_call(
f"observacion/convencional/datos/estacion/{station}", fetch_data
)
self._api_raw_data[RAW_STATIONS][station] = res
return res

async def get_lightnings_map(self) -> dict[str, Any]:
"""Get map with lightning falls (last 6h)."""
Expand All @@ -267,23 +272,29 @@ async def get_specific_forecast_town_daily(
self, town: str, fetch_data: bool = True
) -> dict[str, Any]:
"""Get daily forecast for specific town (daily)."""
return await self.api_call(
res await self.api_call(
f"prediccion/especifica/municipio/diaria/{parse_town_code(town)}",
fetch_data,
)
self._api_raw_data[RAW_FORECAST_DAILY][town] = res
return res

async def get_specific_forecast_town_hourly(
self, town: str, fetch_data: bool = True
) -> dict[str, Any]:
"""Get hourly forecast for specific town (hourly)."""
return await self.api_call(
res await self.api_call(
f"prediccion/especifica/municipio/horaria/{parse_town_code(town)}",
fetch_data,
)
self._api_raw_data[RAW_FORECAST_HOURLY][town] = res
return res

async def get_town(self, town: str) -> dict[str, Any]:
"""Get information about specific town."""
return await self.api_call(f"maestro/municipio/{town}")
res await self.api_call(f"maestro/municipio/{town}")
self._api_raw_data[RAW_TOWNS][town] = res
return res

async def get_town_by_coordinates(
self, latitude: float, longitude: float
Expand Down

0 comments on commit cfe51cb

Please sign in to comment.