Weather.com backend: Fix high/low forecasted temps (#811)

* Weather.com backend: Fix high/low forecasted temps

The values previously being used were the highest/lowest temps within
the last 24 hours, not the forecasted high/low for the current day.

* Interpret null forecasts as empty strings
This commit is contained in:
Erik Johnson 2021-04-10 12:56:05 -05:00 committed by GitHub
parent 7b861a42f5
commit 3976efe5cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -187,6 +187,7 @@ class Weathercom(WeatherBackend):
self.data['update_error'] = self.update_error
return
self.logger.debug('Parsed weather data: %s', self.parser.weather_data)
try:
observed = self.parser.weather_data['getSunV3CurrentObservationsUrlConfig']
# Observation data stored under a sub-key containing the
@ -206,7 +207,7 @@ class Weathercom(WeatherBackend):
return
try:
forecast = self.parser.weather_data['getSunV3CurrentObservationsUrlConfig']
forecast = self.parser.weather_data['getSunV3DailyForecastWithHeadersUrlConfig']
# Same as above, use next(iter(forecast)) to drill down to the
# correct nested dict level.
forecast = forecast[next(iter(forecast))]['data']
@ -251,12 +252,12 @@ class Weathercom(WeatherBackend):
pressure_trend = ''
try:
high_temp = forecast.get('temperatureMax24Hour', '')
high_temp = forecast.get('temperatureMax', [])[0] or ''
except (AttributeError, IndexError):
high_temp = ''
try:
low_temp = forecast.get('temperatureMin24Hour', '')
low_temp = forecast.get('temperatureMin', [])[0] or ''
except (AttributeError, IndexError):
low_temp = ''