diff --git a/homeassistant/components/hue/bridge.py b/homeassistant/components/hue/bridge.py index 2c164e5769a..37089e54b00 100644 --- a/homeassistant/components/hue/bridge.py +++ b/homeassistant/components/hue/bridge.py @@ -1,6 +1,7 @@ """Code to handle a Hue bridge.""" import asyncio from functools import partial +import logging from aiohttp import client_exceptions import aiohue @@ -24,7 +25,8 @@ SCENE_SCHEMA = vol.Schema( {vol.Required(ATTR_GROUP_NAME): cv.string, vol.Required(ATTR_SCENE_NAME): cv.string} ) # How long should we sleep if the hub is busy -HUB_BUSY_SLEEP = 0.01 +HUB_BUSY_SLEEP = 0.5 +_LOGGER = logging.getLogger(__name__) class HueBridge: @@ -123,9 +125,14 @@ class HueBridge: except ( client_exceptions.ClientOSError, client_exceptions.ClientResponseError, + client_exceptions.ServerDisconnectedError, ) as err: - if tries == 3 or ( - # We only retry if it's a server error. So raise on all 4XX errors. + if tries == 3: + _LOGGER.error("Request failed %s times, giving up.", tries) + raise + + # We only retry if it's a server error. So raise on all 4XX errors. + if ( isinstance(err, client_exceptions.ClientResponseError) and err.status < 500 ): diff --git a/homeassistant/components/hue/light.py b/homeassistant/components/hue/light.py index 1678dbbfc62..253c0a2069c 100644 --- a/homeassistant/components/hue/light.py +++ b/homeassistant/components/hue/light.py @@ -5,6 +5,7 @@ from functools import partial import logging import random +from aiohttp import client_exceptions import aiohue import async_timeout @@ -172,7 +173,11 @@ async def async_safe_fetch(bridge, fetch_method): except aiohue.Unauthorized: await bridge.handle_unauthorized_error() raise UpdateFailed - except (asyncio.TimeoutError, aiohue.AiohueException): + except ( + asyncio.TimeoutError, + aiohue.AiohueException, + client_exceptions.ClientError, + ): raise UpdateFailed diff --git a/homeassistant/components/hue/sensor_base.py b/homeassistant/components/hue/sensor_base.py index 0bc7cd53536..ed27cff8eab 100644 --- a/homeassistant/components/hue/sensor_base.py +++ b/homeassistant/components/hue/sensor_base.py @@ -3,6 +3,7 @@ import asyncio from datetime import timedelta import logging +from aiohttp import client_exceptions from aiohue import AiohueException, Unauthorized from aiohue.sensors import TYPE_ZLL_PRESENCE import async_timeout @@ -60,7 +61,7 @@ class SensorManager: except Unauthorized: await self.bridge.handle_unauthorized_error() raise UpdateFailed - except (asyncio.TimeoutError, AiohueException): + except (asyncio.TimeoutError, AiohueException, client_exceptions.ClientError): raise UpdateFailed async def async_register_component(self, binary, async_add_entities):