How to use the pyunifiprotect.NotAuthorized function in pyunifiprotect

To help you get started, we’ve selected a few pyunifiprotect 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 briis / unifiprotect / custom_components / unifiprotect / config_flow.py View on Github external
session = async_create_clientsession(
            self.hass, cookie_jar=CookieJar(unsafe=True)
        )

        unifiprotect = UpvServer(
            session,
            user_input[CONF_HOST],
            user_input[CONF_PORT],
            user_input[CONF_USERNAME],
            user_input[CONF_PASSWORD],
        )

        try:
            unique_id = await unifiprotect.unique_id()
        except NotAuthorized:
            errors["base"] = "connection_error"
            return await self._show_setup_form(errors)
        except NvrError:
            errors["base"] = "nvr_error"
            return await self._show_setup_form(errors)

        entries = self._async_current_entries()
        for entry in entries:
            if entry.data[CONF_ID] == unique_id:
                return self.async_abort(reason="server_exists")

        return self.async_create_entry(
            title=unique_id,
            data={
                CONF_ID: unique_id,
                CONF_HOST: user_input[CONF_HOST],
github briis / unifiprotect / custom_components / unifiprotect / __init__.py View on Github external
events_update_interval = entry.options.get(
        CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
    )

    coordinator = DataUpdateCoordinator(
        hass,
        _LOGGER,
        name=DOMAIN,
        update_method=protectserver.update,
        update_interval=timedelta(seconds=events_update_interval),
    )

    try:
        nvr_info = await protectserver.server_information()
    except NotAuthorized:
        _LOGGER.error(
            "Could not Authorize against Unifi Protect. Please reinstall the Integration."
        )
        return
    except (NvrError, ServerDisconnectedError):
        raise ConfigEntryNotReady

    await coordinator.async_refresh()
    hass.data[DOMAIN][entry.entry_id] = {
        "coordinator": coordinator,
        "upv": protectserver,
        "snapshot_direct": entry.options.get(CONF_SNAPSHOT_DIRECT, False),
    }

    await _async_get_or_create_nvr_device_in_registry(hass, entry, nvr_info)

pyunifiprotect

Unofficial UniFi Protect Python API and CLI

MIT
Latest version published 12 days ago

Package Health Score

78 / 100
Full package analysis

Similar packages