Tomorrowio utc fix (#73102)

* Discard past data using local time instead of UTC

* Tweak changes to fix tests

* Cleanup
This commit is contained in:
lymanepp 2022-06-06 00:10:33 -04:00 committed by Paulus Schoutsen
parent 93aad108a7
commit eef79e2912

View File

@ -198,13 +198,16 @@ class TomorrowioWeatherEntity(TomorrowioEntity, WeatherEntity):
max_forecasts = MAX_FORECASTS[self.forecast_type] max_forecasts = MAX_FORECASTS[self.forecast_type]
forecast_count = 0 forecast_count = 0
# Convert utcnow to local to be compatible with tests
today = dt_util.as_local(dt_util.utcnow()).date()
# 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 raw_forecasts: for forecast in raw_forecasts:
forecast_dt = dt_util.parse_datetime(forecast[TMRW_ATTR_TIMESTAMP]) forecast_dt = dt_util.parse_datetime(forecast[TMRW_ATTR_TIMESTAMP])
# Throw out past data # Throw out past data
if forecast_dt.date() < dt_util.utcnow().date(): if dt_util.as_local(forecast_dt).date() < today:
continue continue
values = forecast["values"] values = forecast["values"]