frenck / python-open-meteo

Asynchronous client for the Open-Meteo API.
MIT License
21 stars 5 forks source link

Use `current` instead of `current_weather` query parameter #660

Open MrEbbinghaus opened 1 week ago

MrEbbinghaus commented 1 week ago

Currently, forecast objects have a current_weather field that only includes condition, temperature and wind, whereas hourly and daily include much more.

The MeteoAPI has a current parameter with a subset of the hourly attributes, which allows more granular queries. (Like temperature, precipitation, humidity, pressure, cloud cover, ...)

Why this is relevant At the moment, the Open-Meteo Home Assistant integration provides precipitation only in the forecasts and wind information only in the entity state. This is a nuisance.

Going forward Open Meteo has their own python SDK / implementation, unfortunately without an async implementation (yet). https://github.com/open-meteo/sdk/tree/main/python https://github.com/open-meteo/python-requests

So maybe this project can only provide the async interface in the future or even be archived in favour of the official implementation. (I'll just innocently mention @patrick-zippenfenig here 😉)

Note on backwards compatibility It seems that current_weather overwrites the current parameter, so you can't just query for more and be backwards compatible. This should be solved by always querying with current=temperature_2m,is_day,weather_code,wind_speed_10m,wind_direction_10m and then mapping the variables to the old CurrentWeather model.

Compare:

current_weather=true

{
  // ...
  "current_weather_units": {
    "time": "iso8601",
    "interval": "seconds",
    "temperature": "°C",
    "windspeed": "km/h",
    "winddirection": "°",
    "is_day": "",
    "weathercode": "wmo code"
  },
  "current_weather": {
    "time": "2024-06-26T13:15",
    "interval": 900,
    "temperature": 24.9,
    "windspeed": 14.5,
    "winddirection": 199,
    "is_day": 1,
    "weathercode": 2
  }
}

current=temperature_2m,is_day,weather_code,wind_speed_10m,wind_direction_10m

{
  // ...
  "current_units": {
    "time": "iso8601",
    "interval": "seconds",
    "temperature_2m": "°C",
    "is_day": "",
    "weather_code": "wmo code",
    "wind_speed_10m": "km/h",
    "wind_direction_10m": "°"
  },
  "current": {
    "time": "2024-06-26T13:15",
    "interval": 900,
    "temperature_2m": 24.9,
    "is_day": 1,
    "weather_code": 2,
    "wind_speed_10m": 14.5,
    "wind_direction_10m": 199
  }
}
patrick-zippenfenig commented 1 week ago

Hi, yes, there are now more options for current weather, but the old format is still supported for backwards compatibility.

I can also provide an async implementation based on aiohttp or httpx. The requests implementation in combination with FlatBuffers as a binary data transport format has been primarily developed for data science use cases. I am not sure how well it interfaces with HA. @MrEbbinghaus Would a simple aiohttp or httpx implementation provide any benefit in this direction?

MrEbbinghaus commented 1 week ago

I guess @frenck should decide on that. He is the expert. :-)