mirror of
https://github.com/home-assistant/core.git
synced 2025-05-25 00:07:20 +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."""
|
"""Weather component that handles meteorological data for your location."""
|
||||||
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Callable, Dict, List, Optional
|
from typing import Any, Callable, Dict, List, Optional
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ def _translate_condition(
|
|||||||
|
|
||||||
def _forecast_dict(
|
def _forecast_dict(
|
||||||
hass: HomeAssistantType,
|
hass: HomeAssistantType,
|
||||||
time: str,
|
forecast_dt: datetime,
|
||||||
use_datetime: bool,
|
use_datetime: bool,
|
||||||
condition: str,
|
condition: str,
|
||||||
precipitation: Optional[float],
|
precipitation: Optional[float],
|
||||||
@ -92,10 +93,7 @@ def _forecast_dict(
|
|||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""Return formatted Forecast dict from ClimaCell forecast data."""
|
"""Return formatted Forecast dict from ClimaCell forecast data."""
|
||||||
if use_datetime:
|
if use_datetime:
|
||||||
translated_condition = _translate_condition(
|
translated_condition = _translate_condition(condition, is_up(hass, forecast_dt))
|
||||||
condition,
|
|
||||||
is_up(hass, dt_util.as_utc(dt_util.parse_datetime(time))),
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
translated_condition = _translate_condition(condition, True)
|
translated_condition = _translate_condition(condition, True)
|
||||||
|
|
||||||
@ -112,7 +110,7 @@ def _forecast_dict(
|
|||||||
wind_speed = distance_convert(wind_speed, LENGTH_MILES, LENGTH_KILOMETERS)
|
wind_speed = distance_convert(wind_speed, LENGTH_MILES, LENGTH_KILOMETERS)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
ATTR_FORECAST_TIME: time,
|
ATTR_FORECAST_TIME: forecast_dt.isoformat(),
|
||||||
ATTR_FORECAST_CONDITION: translated_condition,
|
ATTR_FORECAST_CONDITION: translated_condition,
|
||||||
ATTR_FORECAST_PRECIPITATION: precipitation,
|
ATTR_FORECAST_PRECIPITATION: precipitation,
|
||||||
ATTR_FORECAST_PRECIPITATION_PROBABILITY: precipitation_probability,
|
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
|
# Set default values (in cases where keys don't exist), None will be
|
||||||
# returned. Override properties per forecast type as needed
|
# returned. Override properties per forecast type as needed
|
||||||
for forecast in self.coordinator.data[FORECASTS][self.forecast_type]:
|
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
|
use_datetime = True
|
||||||
condition = self._get_cc_value(forecast, CC_ATTR_CONDITION)
|
condition = self._get_cc_value(forecast, CC_ATTR_CONDITION)
|
||||||
precipitation = self._get_cc_value(forecast, CC_ATTR_PRECIPITATION)
|
precipitation = self._get_cc_value(forecast, CC_ATTR_PRECIPITATION)
|
||||||
@ -290,7 +290,7 @@ class ClimaCellWeatherEntity(ClimaCellEntity, WeatherEntity):
|
|||||||
forecasts.append(
|
forecasts.append(
|
||||||
_forecast_dict(
|
_forecast_dict(
|
||||||
self.hass,
|
self.hass,
|
||||||
timestamp,
|
forecast_dt,
|
||||||
use_datetime,
|
use_datetime,
|
||||||
condition,
|
condition,
|
||||||
precipitation,
|
precipitation,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user