-
-
Notifications
You must be signed in to change notification settings - Fork 37.1k
Add daily weather forecasts to Open-Meteo integration #63677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
|
|
||
| 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 @@ def wind_bearing(self) -> float | str | None: | |
| 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(), | ||
| ) | ||
|
|
||
frenck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if daily.weathercode is not None: | ||
| forecast["condition"] = WMO_TO_HA_CONDITION_MAP.get( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is much benefit from that, as it already is a typed dictionary. |
||
| 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do timezones need to be accounted for here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It already has been accounted for, see the initialization in the unit file