Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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],
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)