Skip to content

Commit

Permalink
Fix/validate host url in config (#192)
Browse files Browse the repository at this point in the history
* auto fix trailing slash in host url

* test scenechange event support
  • Loading branch information
maciej-or authored Jul 31, 2024
1 parent 7e6443c commit 92ae806
Show file tree
Hide file tree
Showing 4 changed files with 1,832 additions and 3 deletions.
10 changes: 7 additions & 3 deletions custom_components/hikvision_next/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Flo

if user_input is not None:
try:
host = user_input[CONF_HOST]
host = user_input[CONF_HOST].rstrip("/")
username = user_input[CONF_USERNAME]
password = user_input[CONF_PASSWORD]
user_input_validated = {
**user_input,
CONF_HOST: host,
}

isapi = ISAPI(host, username, password)
await isapi.get_device_info()

if self._reauth_entry:
self.hass.config_entries.async_update_entry(self._reauth_entry, data=user_input)
self.hass.config_entries.async_update_entry(self._reauth_entry, data=user_input_validated)
self.hass.async_create_task(self.hass.config_entries.async_reload(self._reauth_entry.entry_id))
return self.async_abort(reason="reauth_successful")

Expand All @@ -82,7 +86,7 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Flo
_LOGGER.error("Unexpected %s %s", {type(ex).__name__}, ex)
errors["base"] = f"Unexpected {type(ex).__name__}: {ex}"
else:
return self.async_create_entry(title=isapi.device_info.name, data=user_input)
return self.async_create_entry(title=isapi.device_info.name, data=user_input_validated)

schema = await self.get_schema(user_input or {})
return self.async_show_form(step_id="user", data_schema=schema, errors=errors)
Expand Down
Loading

0 comments on commit 92ae806

Please sign in to comment.