Fix timezones in Environment Canada hourly forecasts (#51917)

This commit is contained in:
Michael Davie 2021-06-28 06:57:07 -04:00 committed by GitHub
parent 90e9216e9a
commit 594bcbcf7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -232,19 +232,20 @@ def get_forecast(ec_data, forecast_type):
)
elif forecast_type == "hourly":
hours = ec_data.hourly_forecasts
for hour in range(0, 24):
for hour in ec_data.hourly_forecasts:
forecast_array.append(
{
ATTR_FORECAST_TIME: dt.as_local(
datetime.datetime.strptime(hours[hour]["period"], "%Y%m%d%H%M")
).isoformat(),
ATTR_FORECAST_TEMP: int(hours[hour]["temperature"]),
ATTR_FORECAST_TIME: datetime.datetime.strptime(
hour["period"], "%Y%m%d%H%M%S"
)
.replace(tzinfo=dt.UTC)
.isoformat(),
ATTR_FORECAST_TEMP: int(hour["temperature"]),
ATTR_FORECAST_CONDITION: icon_code_to_condition(
int(hours[hour]["icon_code"])
int(hour["icon_code"])
),
ATTR_FORECAST_PRECIPITATION_PROBABILITY: int(
hours[hour]["precip_probability"]
hour["precip_probability"]
),
}
)