Support more errors to better do retries in UniFi (#44108)
parent
42d1644762
commit
3986df63dc
|
@ -397,7 +397,12 @@ class UniFiController:
|
||||||
await self.api.login()
|
await self.api.login()
|
||||||
self.api.start_websocket()
|
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)
|
self.hass.loop.call_later(RETRY_TIMER, self.reconnect)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -464,7 +469,12 @@ async def get_controller(
|
||||||
LOGGER.warning("Connected to UniFi at %s but not registered.", host)
|
LOGGER.warning("Connected to UniFi at %s but not registered.", host)
|
||||||
raise AuthenticationRequired from err
|
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)
|
LOGGER.error("Error connecting to the UniFi controller at %s", host)
|
||||||
raise CannotConnect from err
|
raise CannotConnect from err
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Ubiquiti UniFi",
|
"name": "Ubiquiti UniFi",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/unifi",
|
"documentation": "https://www.home-assistant.io/integrations/unifi",
|
||||||
"requirements": ["aiounifi==25"],
|
"requirements": ["aiounifi==26"],
|
||||||
"codeowners": ["@Kane610"],
|
"codeowners": ["@Kane610"],
|
||||||
"quality_scale": "platinum"
|
"quality_scale": "platinum"
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ aioshelly==0.5.1
|
||||||
aioswitcher==1.2.1
|
aioswitcher==1.2.1
|
||||||
|
|
||||||
# homeassistant.components.unifi
|
# homeassistant.components.unifi
|
||||||
aiounifi==25
|
aiounifi==26
|
||||||
|
|
||||||
# homeassistant.components.yandex_transport
|
# homeassistant.components.yandex_transport
|
||||||
aioymaps==1.1.0
|
aioymaps==1.1.0
|
||||||
|
|
|
@ -140,7 +140,7 @@ aioshelly==0.5.1
|
||||||
aioswitcher==1.2.1
|
aioswitcher==1.2.1
|
||||||
|
|
||||||
# homeassistant.components.unifi
|
# homeassistant.components.unifi
|
||||||
aiounifi==25
|
aiounifi==26
|
||||||
|
|
||||||
# homeassistant.components.yandex_transport
|
# homeassistant.components.yandex_transport
|
||||||
aioymaps==1.1.0
|
aioymaps==1.1.0
|
||||||
|
|
|
@ -295,6 +295,22 @@ async def test_get_controller_login_failed(hass):
|
||||||
await get_controller(hass, **CONTROLLER_DATA)
|
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):
|
async def test_get_controller_controller_unavailable(hass):
|
||||||
"""Check that get_controller can handle controller being unavailable."""
|
"""Check that get_controller can handle controller being unavailable."""
|
||||||
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
with patch("aiounifi.Controller.check_unifi_os", return_value=True), patch(
|
||||||
|
|
Loading…
Reference in New Issue