mirror of
https://github.com/home-assistant/core.git
synced 2025-05-21 22:37:07 +00:00
Convert climacell forecast timestamp to isoformat so that UI shows the right times (#47286)
This commit is contained in:
parent
42af775f53
commit
c327f3fc42
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user