Catch more Hue errors (#32275)

This commit is contained in:
Paulus Schoutsen 2020-02-27 12:53:36 -08:00 committed by GitHub
parent ecd076c5e4
commit 5a56d0ec1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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
):