From c327f3fc42744bdda053aac996dc2095b61b45d0 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Tue, 2 Mar 2021 16:25:09 -0500 Subject: [PATCH] Convert climacell forecast timestamp to isoformat so that UI shows the right times (#47286) --- homeassistant/components/climacell/weather.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/climacell/weather.py b/homeassistant/components/climacell/weather.py index da3282108a5..c77bbfbd50a 100644 --- a/homeassistant/components/climacell/weather.py +++ b/homeassistant/components/climacell/weather.py @@ -1,4 +1,5 @@ """Weather component that handles meteorological data for your location.""" +from datetime import datetime import logging from typing import Any, Callable, Dict, List, Optional @@ -80,7 +81,7 @@ def _translate_condition( def _forecast_dict( hass: HomeAssistantType, - time: str, + forecast_dt: datetime, use_datetime: bool, condition: str, precipitation: Optional[float], @@ -92,10 +93,7 @@ def _forecast_dict( ) -> Dict[str, Any]: """Return formatted Forecast dict from ClimaCell forecast data.""" if use_datetime: - translated_condition = _translate_condition( - condition, - is_up(hass, dt_util.as_utc(dt_util.parse_datetime(time))), - ) + translated_condition = _translate_condition(condition, is_up(hass, forecast_dt)) else: translated_condition = _translate_condition(condition, True) @@ -112,7 +110,7 @@ def _forecast_dict( wind_speed = distance_convert(wind_speed, LENGTH_MILES, LENGTH_KILOMETERS) data = { - ATTR_FORECAST_TIME: time, + ATTR_FORECAST_TIME: forecast_dt.isoformat(), ATTR_FORECAST_CONDITION: translated_condition, ATTR_FORECAST_PRECIPITATION: precipitation, ATTR_FORECAST_PRECIPITATION_PROBABILITY: precipitation_probability, @@ -246,7 +244,9 @@ class ClimaCellWeatherEntity(ClimaCellEntity, WeatherEntity): # Set default values (in cases where keys don't exist), None will be # returned. Override properties per forecast type as needed for forecast in self.coordinator.data[FORECASTS][self.forecast_type]: - timestamp = self._get_cc_value(forecast, CC_ATTR_TIMESTAMP) + forecast_dt = dt_util.parse_datetime( + self._get_cc_value(forecast, CC_ATTR_TIMESTAMP) + ) use_datetime = True condition = self._get_cc_value(forecast, CC_ATTR_CONDITION) precipitation = self._get_cc_value(forecast, CC_ATTR_PRECIPITATION) @@ -290,7 +290,7 @@ class ClimaCellWeatherEntity(ClimaCellEntity, WeatherEntity): forecasts.append( _forecast_dict( self.hass, - timestamp, + forecast_dt, use_datetime, condition, precipitation,