diff --git a/homeassistant/components/sensor/openweathermap.py b/homeassistant/components/sensor/openweathermap.py index 944ee101d13..2072251c205 100755 --- a/homeassistant/components/sensor/openweathermap.py +++ b/homeassistant/components/sensor/openweathermap.py @@ -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") diff --git a/homeassistant/components/weather/openweathermap.py b/homeassistant/components/weather/openweathermap.py index 6442a0342a5..a50e160cddb 100644 --- a/homeassistant/components/weather/openweathermap.py +++ b/homeassistant/components/weather/openweathermap.py @@ -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")