10000 Support more errors to better do retries in UniFi by Kane610 · Pull Request #44108 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support more errors to better do retries in UniFi #44108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions homeassistant/components/unifi/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,12 @@ async def async_reconnect(self) -> None:
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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/unifi/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/components/unifi/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
0