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."""
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
):

View File

@ -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

View File

@ -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):