From 594bcbcf7a3edeba725397273e0a06b7f4e71ebf Mon Sep 17 00:00:00 2001 From: Michael Davie Date: Mon, 28 Jun 2021 06:57:07 -0400 Subject: [PATCH] Fix timezones in Environment Canada hourly forecasts (#51917) --- .../components/environment_canada/weather.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/environment_canada/weather.py b/homeassistant/components/environment_canada/weather.py index 5301843fc0a..a4a8a02cee9 100644 --- a/homeassistant/components/environment_canada/weather.py +++ b/homeassistant/components/environment_canada/weather.py @@ -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"] ), } )