Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_get_controller_controller_unavailable(hass):
"""Check that get_controller can handle controller being unavailable."""
result = None
with patch("aiounifi.Controller.login", side_effect=aiounifi.RequestError):
try:
result = await unifi.controller.get_controller(hass, **CONTROLLER_DATA)
except unifi.errors.CannotConnect:
pass
assert result is None
port=port,
site=site,
websession=session,
sslcontext=sslcontext,
)
try:
with async_timeout.timeout(10):
await controller.login()
return controller
except aiounifi.Unauthorized:
LOGGER.warning("Connected to UniFi at %s but not registered.", host)
raise AuthenticationRequired
except (asyncio.TimeoutError, aiounifi.RequestError):
LOGGER.error("Error connecting to the UniFi controller at %s", host)
raise CannotConnect
except aiounifi.AiounifiException:
LOGGER.exception("Unknown UniFi communication error occurred")
raise AuthenticationRequired