Skip to content

Commit

Permalink
Fix first Hourly weather conditions if missing (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyKh authored May 30, 2023
1 parent 6d09ccc commit 8778623
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion custom_components/ims/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/t0mer/ims-custom-component/issues",
"requirements": ["weatheril>=0.31.0"],
"version": "0.1.13"
"version": "0.1.14"
}
18 changes: 10 additions & 8 deletions custom_components/ims/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,26 +269,28 @@ def forecast(self):
if self._mode == "daily":
data = [
{
ATTR_FORECAST_TIME: entry.date.astimezone(pytz.UTC).isoformat(),
ATTR_FORECAST_NATIVE_TEMP: entry.maximum_temperature,
ATTR_FORECAST_NATIVE_TEMP_LOW: entry.minimum_temperature,
ATTR_FORECAST_CONDITION: WEATHER_CODE_TO_CONDITION[entry.weather_code],
ATTR_FORECAST_TIME: daily_forecast.date.astimezone(pytz.UTC).isoformat(),
ATTR_FORECAST_NATIVE_TEMP: daily_forecast.maximum_temperature,
ATTR_FORECAST_NATIVE_TEMP_LOW: daily_forecast.minimum_temperature,
ATTR_FORECAST_CONDITION: WEATHER_CODE_TO_CONDITION[daily_forecast.weather_code],
}
for entry in self._weather_coordinator.data.forecast.days
for daily_forecast in self._weather_coordinator.data.forecast.days
]
else:
last_weather_code = None
for entry in self._weather_coordinator.data.forecast.days:
for hourly_forecast in entry.hours:
for daily_forecast in self._weather_coordinator.data.forecast.days:
for hourly_forecast in daily_forecast.hours:
if hourly_forecast.weather_code and hourly_forecast.weather_code != "0":
last_weather_code = hourly_forecast.weather_code
elif not last_weather_code:
last_weather_code = daily_forecast.weather_code
data.append(
{
ATTR_FORECAST_TIME: hourly_forecast.forecast_time.astimezone(
pytz.UTC
).isoformat(),
ATTR_FORECAST_NATIVE_TEMP: hourly_forecast.temperature,
ATTR_FORECAST_NATIVE_TEMP_LOW: entry.minimum_temperature,
ATTR_FORECAST_NATIVE_TEMP_LOW: daily_forecast.minimum_temperature,
ATTR_FORECAST_CONDITION: WEATHER_CODE_TO_CONDITION[last_weather_code],
ATTR_FORECAST_NATIVE_PRECIPITATION: hourly_forecast.rain,
ATTR_FORECAST_WIND_BEARING: WIND_DIRECTIONS[hourly_forecast.wind_direction_id],
Expand Down

0 comments on commit 8778623

Please sign in to comment.