Catch more Hue errors (#32275)

pull/32282/head
Paulus Schoutsen 2020-02-27 12:53:36 -08:00
parent a5d9e89d08
commit c0394232f3
3 changed files with 18 additions and 5 deletions

View File

@ -1,6 +1,7 @@
"""Code to handle a Hue bridge.""" """Code to handle a Hue bridge."""
import asyncio import asyncio
from functools import partial from functools import partial
import logging
from aiohttp import client_exceptions from aiohttp import client_exceptions
import aiohue import aiohue
@ -24,7 +25,8 @@ SCENE_SCHEMA = vol.Schema(
{vol.Required(ATTR_GROUP_NAME): cv.string, vol.Required(ATTR_SCENE_NAME): cv.string} {vol.Required(ATTR_GROUP_NAME): cv.string, vol.Required(ATTR_SCENE_NAME): cv.string}
) )
# How long should we sleep if the hub is busy # 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: class HueBridge:
@ -123,9 +125,14 @@ class HueBridge:
except ( except (
client_exceptions.ClientOSError, client_exceptions.ClientOSError,
client_exceptions.ClientResponseError, client_exceptions.ClientResponseError,
client_exceptions.ServerDisconnectedError,
) as err: ) as err:
if tries == 3 or ( if tries == 3:
# We only retry if it's a server error. So raise on all 4XX errors. _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) isinstance(err, client_exceptions.ClientResponseError)
and err.status < 500 and err.status < 500
): ):

View File

@ -5,6 +5,7 @@ from functools import partial
import logging import logging
import random import random
from aiohttp import client_exceptions
import aiohue import aiohue
import async_timeout import async_timeout
@ -172,7 +173,11 @@ async def async_safe_fetch(bridge, fetch_method):
except aiohue.Unauthorized: except aiohue.Unauthorized:
await bridge.handle_unauthorized_error() await bridge.handle_unauthorized_error()
raise UpdateFailed raise UpdateFailed
except (asyncio.TimeoutError, aiohue.AiohueException): except (
asyncio.TimeoutError,
aiohue.AiohueException,
client_exceptions.ClientError,
):
raise UpdateFailed raise UpdateFailed

View File

@ -3,6 +3,7 @@ import asyncio
from datetime import timedelta from datetime import timedelta
import logging import logging
from aiohttp import client_exceptions
from aiohue import AiohueException, Unauthorized from aiohue import AiohueException, Unauthorized
from aiohue.sensors import TYPE_ZLL_PRESENCE from aiohue.sensors import TYPE_ZLL_PRESENCE
import async_timeout import async_timeout
@ -60,7 +61,7 @@ class SensorManager:
except Unauthorized: except Unauthorized:
await self.bridge.handle_unauthorized_error() await self.bridge.handle_unauthorized_error()
raise UpdateFailed raise UpdateFailed
except (asyncio.TimeoutError, AiohueException): except (asyncio.TimeoutError, AiohueException, client_exceptions.ClientError):
raise UpdateFailed raise UpdateFailed
async def async_register_component(self, binary, async_add_entities): async def async_register_component(self, binary, async_add_entities):