How to use the aiounifi.Unauthorized function in aiounifi

To help you get started, we’ve selected a few aiounifi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / home-assistant / tests / components / unifi / test_controller.py View on Github external
async def test_get_controller_login_failed(hass):
    """Check that get_controller can handle a failed login."""
    result = None
    with patch("aiounifi.Controller.login", side_effect=aiounifi.Unauthorized):
        try:
            result = await unifi.controller.get_controller(hass, **CONTROLLER_DATA)
        except unifi.errors.AuthenticationRequired:
            pass
        assert result is None
github home-assistant / home-assistant / homeassistant / components / unifi / controller.py View on Github external
controller = aiounifi.Controller(
        host,
        username=username,
        password=password,
        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

aiounifi

Python library for communicating with UniFi Network Controller API

MIT
Latest version published 8 days ago

Package Health Score

75 / 100
Full package analysis

Similar packages