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 async_step_user(self, user_input=None):
"""Handle a flow initiated by the user."""
if user_input is None:
return await self._show_setup_form(user_input)
errors = {}
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)
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
"""Set up the Unifi Protect config entries."""
if not entry.options:
hass.config_entries.async_update_entry(
entry,
options={
CONF_SCAN_INTERVAL: entry.data.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
),
CONF_SNAPSHOT_DIRECT: entry.data.get(CONF_SNAPSHOT_DIRECT, False),
},
)
session = async_create_clientsession(hass, cookie_jar=CookieJar(unsafe=True))
protectserver = UpvServer(
session,
entry.data[CONF_HOST],
entry.data[CONF_PORT],
entry.data[CONF_USERNAME],
entry.data[CONF_PASSWORD],
)
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = protectserver
_LOGGER.debug("Connect to Unfi Protect")
events_update_interval = entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
)
coordinator = DataUpdateCoordinator(
hass,