mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +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):
|
def update(self):
|
||||||
"""Get the latest data from OWM and updates the states."""
|
"""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
|
data = self.owa_client.data
|
||||||
fc_data = self.owa_client.fc_data
|
fc_data = self.owa_client.fc_data
|
||||||
|
|
||||||
@ -185,10 +192,15 @@ class WeatherData(object):
|
|||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from OpenWeatherMap."""
|
"""Get the latest data from OpenWeatherMap."""
|
||||||
|
from pyowm.exceptions.api_call_error import APICallError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obs = self.owm.weather_at_coords(self.latitude, self.longitude)
|
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
|
obs = None
|
||||||
|
|
||||||
if obs is None:
|
if obs is None:
|
||||||
_LOGGER.warning("Failed to fetch data")
|
_LOGGER.warning("Failed to fetch data")
|
||||||
return
|
return
|
||||||
@ -200,5 +212,5 @@ class WeatherData(object):
|
|||||||
obs = self.owm.three_hours_forecast_at_coords(
|
obs = self.owm.three_hours_forecast_at_coords(
|
||||||
self.latitude, self.longitude)
|
self.latitude, self.longitude)
|
||||||
self.fc_data = obs.get_forecast()
|
self.fc_data = obs.get_forecast()
|
||||||
except TypeError:
|
except (ConnectionResetError, TypeError):
|
||||||
_LOGGER.warning("Failed to fetch forecast")
|
_LOGGER.warning("Failed to fetch forecast")
|
||||||
|
@ -142,8 +142,15 @@ class OpenWeatherMapWeather(WeatherEntity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from OWM and updates the states."""
|
"""Get the latest data from OWM and updates the states."""
|
||||||
self._owm.update()
|
from pyowm.exceptions.api_call_error import APICallError
|
||||||
self._owm.update_forecast()
|
|
||||||
|
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.data = self._owm.data
|
||||||
self.forecast_data = self._owm.forecast_data
|
self.forecast_data = self._owm.forecast_data
|
||||||
|
|
||||||
@ -172,8 +179,15 @@ class WeatherData(object):
|
|||||||
@Throttle(MIN_TIME_BETWEEN_FORECAST_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_FORECAST_UPDATES)
|
||||||
def update_forecast(self):
|
def update_forecast(self):
|
||||||
"""Get the lastest forecast from OpenWeatherMap."""
|
"""Get the lastest forecast from OpenWeatherMap."""
|
||||||
fcd = self.owm.three_hours_forecast_at_coords(
|
from pyowm.exceptions.api_call_error import APICallError
|
||||||
self.latitude, self.longitude)
|
|
||||||
|
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:
|
if fcd is None:
|
||||||
_LOGGER.warning("Failed to fetch forecast data from OWM")
|
_LOGGER.warning("Failed to fetch forecast data from OWM")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user