How to use the aiounifi.LoginRequired 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_failed_update_successful_login(hass):
    """Running update can login when requested."""
    controller = await setup_unifi_integration(
        hass,
        ENTRY_CONFIG,
        options={},
        sites=SITES,
        clients_response=[],
        devices_response=[],
        clients_all_response=[],
    )

    with patch.object(
        controller.api.clients, "update", side_effect=aiounifi.LoginRequired
    ), patch.object(controller.api, "login", return_value=Mock(True)):
        await controller.async_update()
    await hass.async_block_till_done()

    assert controller.available is True
github home-assistant / home-assistant / tests / components / unifi / test_controller.py View on Github external
async def test_failed_update_failed_login(hass):
    """Running update can handle a failed login."""
    controller = await setup_unifi_integration(
        hass,
        ENTRY_CONFIG,
        options={},
        sites=SITES,
        clients_response=[],
        devices_response=[],
        clients_all_response=[],
    )

    with patch.object(
        controller.api.clients, "update", side_effect=aiounifi.LoginRequired
    ), patch.object(controller.api, "login", side_effect=aiounifi.AiounifiException):
        await controller.async_update()
    await hass.async_block_till_done()

    assert controller.available is False
github home-assistant / home-assistant / homeassistant / components / unifi / controller.py View on Github external
async def async_update(self):
        """Update UniFi controller information."""
        failed = False

        try:
            with async_timeout.timeout(10):
                await self.api.clients.update()
                await self.api.devices.update()
                if self.option_block_clients:
                    await self.api.clients_all.update()

        except aiounifi.LoginRequired:
            try:
                with async_timeout.timeout(5):
                    await self.api.login()

            except (asyncio.TimeoutError, aiounifi.AiounifiException):
                failed = True
                if self.available:
                    LOGGER.error("Unable to reach controller %s", self.host)
                    self.available = False

        except (asyncio.TimeoutError, aiounifi.AiounifiException):
            failed = True
            if self.available:
                LOGGER.error("Unable to reach controller %s", self.host)
                self.available = False

aiounifi

Python library for communicating with UniFi Network Controller API

MIT
Latest version published 2 months ago

Package Health Score

75 / 100
Full package analysis

Similar packages