diff --git a/homeassistant/components/unifi/controller.py b/homeassistant/components/unifi/controller.py index a4435ccfecf..30b82c65c85 100644 --- a/homeassistant/components/unifi/controller.py +++ b/homeassistant/components/unifi/controller.py @@ -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 diff --git a/homeassistant/components/unifi/manifest.json b/homeassistant/components/unifi/manifest.json index 48c080f82f7..94b1c90f4f3 100644 --- a/homeassistant/components/unifi/manifest.json +++ b/homeassistant/components/unifi/manifest.json @@ -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" } diff --git a/requirements_all.txt b/requirements_all.txt index 65bd29256ab..79f1472043d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 8497227b164..9604d0579af 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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 diff --git a/tests/components/unifi/test_controller.py b/tests/components/unifi/test_controller.py index 83732601cd6..8d5cb85bf9f 100644 --- a/tests/components/unifi/test_controller.py +++ b/tests/components/unifi/test_controller.py @@ -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(