mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
handle OWM API error calls (#9865)
This commit is contained in:
parent
0362a76cd6
commit
ac256d5943
@ -125,7 +125,14 @@ class OpenWeatherMapSensor(Entity):
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from OWM and updates the states."""
|
||||
self.owa_client.update()
|
||||
from pyowm.exceptions.api_call_error import APICallError
|
||||
|
||||
try:
|
||||
self.owa_client.update()
|
||||
except APICallError:
|
||||
_LOGGER.error("Exception when calling OWM web API to update data")
|
||||
return
|
||||
|
||||
data = self.owa_client.data
|
||||
fc_data = self.owa_client.fc_data
|
||||
|
||||
@ -185,10 +192,15 @@ class WeatherData(object):
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
def update(self):
|
||||
"""Get the latest data from OpenWeatherMap."""
|
||||
from pyowm.exceptions.api_call_error import APICallError
|
||||
|
||||
try:
|
||||
obs = self.owm.weather_at_coords(self.latitude, self.longitude)
|
||||
except TypeError:
|
||||
except (APICallError, TypeError):
|
||||
_LOGGER.error("Exception when calling OWM web API "
|
||||
"to get weather at coords")
|
||||
obs = None
|
||||
|
||||
if obs is None:
|
||||
_LOGGER.warning("Failed to fetch data")
|
||||
return
|
||||
@ -200,5 +212,5 @@ class WeatherData(object):
|
||||
obs = self.owm.three_hours_forecast_at_coords(
|
||||
self.latitude, self.longitude)
|
||||
self.fc_data = obs.get_forecast()
|
||||
except TypeError:
|
||||
except (ConnectionResetError, TypeError):
|
||||
_LOGGER.warning("Failed to fetch forecast")
|
||||
|
@ -142,8 +142,15 @@ class OpenWeatherMapWeather(WeatherEntity):
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from OWM and updates the states."""
|
||||
self._owm.update()
|
||||
self._owm.update_forecast()
|
||||
from pyowm.exceptions.api_call_error import APICallError
|
||||
|
||||
try:
|
||||
self._owm.update()
|
||||
self._owm.update_forecast()
|
||||
except APICallError:
|
||||
_LOGGER.error("Exception when calling OWM web API to update data")
|
||||
return
|
||||
|
||||
self.data = self._owm.data
|
||||
self.forecast_data = self._owm.forecast_data
|
||||
|
||||
@ -172,8 +179,15 @@ class WeatherData(object):
|
||||
@Throttle(MIN_TIME_BETWEEN_FORECAST_UPDATES)
|
||||
def update_forecast(self):
|
||||
"""Get the lastest forecast from OpenWeatherMap."""
|
||||
fcd = self.owm.three_hours_forecast_at_coords(
|
||||
self.latitude, self.longitude)
|
||||
from pyowm.exceptions.api_call_error import APICallError
|
||||
|
||||
try:
|
||||
fcd = self.owm.three_hours_forecast_at_coords(
|
||||
self.latitude, self.longitude)
|
||||
except APICallError:
|
||||
_LOGGER.error("Exception when calling OWM web API "
|
||||
"to update forecast")
|
||||
return
|
||||
|
||||
if fcd is None:
|
||||
_LOGGER.warning("Failed to fetch forecast data from OWM")
|
||||
|
Loading…
x
Reference in New Issue
Block a user