Support more errors to better do retries in UniFi (#44108)

pull/44175/head
Robert Svensson 2020-12-10 21:25:50 +01:00 committed by Franck Nijhof
parent 42d1644762
commit 3986df63dc
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
5 changed files with 31 additions and 5 deletions

View File

@ -397,7 +397,12 @@ class UniFiController:
await self.api.login()
self.api.start_websocket()
except (asyncio.TimeoutError, aiounifi.AiounifiException):
except (
asyncio.TimeoutError,
aiounifi.BadGateway,
aiounifi.ServiceUnavailable,
aiounifi.AiounifiException,
):
self.hass.loop.call_later(RETRY_TIMER, self.reconnect)
@callback
@ -464,7 +469,12 @@ async def get_controller(
LOGGER.warning("Connected to UniFi at %s but not registered.", host)
raise AuthenticationRequired from err
except (asyncio.TimeoutError, aiounifi.RequestError) as err:
except (
asyncio.TimeoutError,
aiounifi.BadGateway,
aiounifi.ServiceUnavailable,
aiounifi.RequestError,
) as err:
LOGGER.error("Error connecting to the UniFi controller at %s", host)
raise CannotConnect from err

View File

@ -3,7 +3,7 @@
"name": "Ubiquiti UniFi",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/unifi",
"requirements": ["aiounifi==25"],
"requirements": ["aiounifi==26"],
"codeowners": ["@Kane610"],
"quality_scale": "platinum"
}

View File

@ -224,7 +224,7 @@ aioshelly==0.5.1
aioswitcher==1.2.1
# homeassistant.components.unifi
aiounifi==25
aiounifi==26
# homeassistant.components.yandex_transport
aioymaps==1.1.0

View File

@ -140,7 +140,7 @@ aioshelly==0.5.1
aioswitcher==1.2.1
# homeassistant.components.unifi
aiounifi==25
aiounifi==26
# homeassistant.components.yandex_transport
aioymaps==1.1.0

View File

@ -295,6 +295,22 @@ async def test_get_controller_login_failed(hass):
await get_controller(hass, **CONTROLLER_DATA)
async def test_get_controller_controller_bad_gateway(hass):
"""Check that get_controller can handle controller being unavailable."""
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
"aiounifi.Controller.login", side_effect=aiounifi.BadGateway
), pytest.raises(CannotConnect):
await get_controller(hass, **CONTROLLER_DATA)
async def test_get_controller_controller_service_unavailable(hass):
"""Check that get_controller can handle controller being unavailable."""
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
"aiounifi.Controller.login", side_effect=aiounifi.ServiceUnavailable
), pytest.raises(CannotConnect):
await get_controller(hass, **CONTROLLER_DATA)
async def test_get_controller_controller_unavailable(hass):
"""Check that get_controller can handle controller being unavailable."""
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(