Convert climacell forecast timestamp to isoformat so that UI shows the right times (#47286)

This commit is contained in:
Raman Gupta 2021-03-02 16:25:09 -05:00 committed by GitHub
parent 42af775f53
commit c327f3fc42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,