From cfe51cb8ba053c96e744380d729d716ba3fe3c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Wed, 23 Aug 2023 12:25:04 +0200 Subject: [PATCH] interface: add raw API data --- aemet_opendata/interface.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/aemet_opendata/interface.py b/aemet_opendata/interface.py index c889a43..bd71255 100644 --- a/aemet_opendata/interface.py +++ b/aemet_opendata/interface.py @@ -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, @@ -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 @@ -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.""" @@ -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).""" @@ -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