Add daily weather forecasts to Open-Meteo integration (#63677)
parent
ddb6f36890
commit
5a1e5e1cef
|
@ -1,7 +1,15 @@
|
|||
"""Support for Open-Meteo."""
|
||||
from __future__ import annotations
|
||||
|
||||
from open_meteo import Forecast, OpenMeteo, OpenMeteoError
|
||||
from open_meteo import (
|
||||
DailyParameters,
|
||||
Forecast,
|
||||
OpenMeteo,
|
||||
OpenMeteoError,
|
||||
PrecipitationUnit,
|
||||
TemperatureUnit,
|
||||
WindSpeedUnit,
|
||||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_ZONE, Platform
|
||||
|
@ -29,6 +37,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
latitude=zone.attributes[ATTR_LATITUDE],
|
||||
longitude=zone.attributes[ATTR_LONGITUDE],
|
||||
current_weather=True,
|
||||
daily=[
|
||||
DailyParameters.PRECIPITATION_SUM,
|
||||
DailyParameters.TEMPERATURE_2M_MAX,
|
||||
DailyParameters.TEMPERATURE_2M_MIN,
|
||||
DailyParameters.WEATHER_CODE,
|
||||
DailyParameters.WIND_DIRECTION_10M_DOMINANT,
|
||||
DailyParameters.WIND_SPEED_10M_MAX,
|
||||
],
|
||||
precipitation_unit=PrecipitationUnit.MILLIMETERS,
|
||||
temperature_unit=TemperatureUnit.CELSIUS,
|
||||
timezone="UTC",
|
||||
wind_speed_unit=WindSpeedUnit.KILOMETERS_PER_HOUR,
|
||||
)
|
||||
except OpenMeteoError as err:
|
||||
raise UpdateFailed("Open-Meteo API communication error") from err
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from open_meteo import Forecast as OpenMeteoForecast
|
||||
|
||||
from homeassistant.components.weather import WeatherEntity
|
||||
from homeassistant.components.weather import Forecast, WeatherEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -78,3 +78,41 @@ class OpenMeteoWeatherEntity(CoordinatorEntity, WeatherEntity):
|
|||
if not self.coordinator.data.current_weather:
|
||||
return None
|
||||
return self.coordinator.data.current_weather.wind_direction
|
||||
|
||||
@property
|
||||
def forecast(self) -> list[Forecast] | None:
|
||||
"""Return the forecast in native units."""
|
||||
if self.coordinator.data.daily is None:
|
||||
return None
|
||||
|
||||
forecasts: list[Forecast] = []
|
||||
daily = self.coordinator.data.daily
|
||||
for index, time in enumerate(self.coordinator.data.daily.time):
|
||||
|
||||
forecast = Forecast(
|
||||
datetime=time.isoformat(),
|
||||
)
|
||||
|
||||
if daily.weathercode is not None:
|
||||
forecast["condition"] = WMO_TO_HA_CONDITION_MAP.get(
|
||||
daily.weathercode[index]
|
||||
)
|
||||
|
||||
if daily.precipitation_sum is not None:
|
||||
forecast["precipitation"] = daily.precipitation_sum[index]
|
||||
|
||||
if daily.temperature_2m_max is not None:
|
||||
forecast["temperature"] = daily.temperature_2m_max[index]
|
||||
|
||||
if daily.temperature_2m_min is not None:
|
||||
forecast["templow"] = daily.temperature_2m_min[index]
|
||||
|
||||
if daily.wind_direction_10m_dominant is not None:
|
||||
forecast["wind_bearing"] = daily.wind_direction_10m_dominant[index]
|
||||
|
||||
if daily.wind_speed_10m_max is not None:
|
||||
forecast["wind_speed"] = daily.wind_speed_10m_max[index]
|
||||
|
||||
forecasts.append(forecast)
|
||||
|
||||
return forecasts
|
||||
|
|
Loading…
Reference in New Issue