From 5677adc1040b7613d45a7fdd4dc9a17d592825f3 Mon Sep 17 00:00:00 2001 From: Philip Allgaier Date: Fri, 15 Jan 2021 23:32:38 +0100 Subject: [PATCH] Fix all forecast datetime values in OpenWeatherMap (#45202) --- homeassistant/components/openweathermap/sensor.py | 10 +--------- .../openweathermap/weather_update_coordinator.py | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/openweathermap/sensor.py b/homeassistant/components/openweathermap/sensor.py index b1ba4ab7625..39c50c3b941 100644 --- a/homeassistant/components/openweathermap/sensor.py +++ b/homeassistant/components/openweathermap/sensor.py @@ -1,10 +1,7 @@ """Support for the OpenWeatherMap (OWM) service.""" -import datetime - from .abstract_owm_sensor import AbstractOpenWeatherMapSensor from .const import ( ATTR_API_FORECAST, - DEVICE_CLASS_TIMESTAMP, DOMAIN, ENTRY_NAME, ENTRY_WEATHER_COORDINATOR, @@ -98,10 +95,5 @@ class OpenWeatherMapForecastSensor(AbstractOpenWeatherMapSensor): """Return the state of the device.""" forecasts = self._weather_coordinator.data.get(ATTR_API_FORECAST) if forecasts is not None and len(forecasts) > 0: - value = forecasts[0].get(self._sensor_type, None) - if self._device_class is DEVICE_CLASS_TIMESTAMP: - value = datetime.datetime.fromtimestamp( - value, datetime.timezone.utc - ).isoformat() - return value + return forecasts[0].get(self._sensor_type, None) return None diff --git a/homeassistant/components/openweathermap/weather_update_coordinator.py b/homeassistant/components/openweathermap/weather_update_coordinator.py index 901ea029743..93db4ca26d8 100644 --- a/homeassistant/components/openweathermap/weather_update_coordinator.py +++ b/homeassistant/components/openweathermap/weather_update_coordinator.py @@ -139,7 +139,7 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator): def _convert_forecast(self, entry): forecast = { - ATTR_FORECAST_TIME: entry.reference_time("unix"), + ATTR_FORECAST_TIME: dt.utc_from_timestamp(entry.reference_time("unix")), ATTR_FORECAST_PRECIPITATION: self._calc_precipitation( entry.rain, entry.snow ),