-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Migrate Hikvision integration to config flow #158279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joostlek
merged 31 commits into
home-assistant:dev
from
ptarjan:claude/migrate-hikvision-integration-012bm7PWpikgSddSEixptrqe
Dec 16, 2025
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d27343f
Migrate Hikvision integration to config flow with NVR support
ptarjan 045f3bf
Address reviewer feedback: use _attr_name for entity naming
ptarjan 8138cd3
Add YAML import flow for backward compatibility
ptarjan 92e00cf
Add tests for YAML import flow
ptarjan 7c4bf8b
Remove NVR helper function calls from setup
ptarjan dd500c1
Remove unused helpers.py file
ptarjan 333556b
Apply suggestion from @mik-laj
ptarjan 4b092d4
Fix ruff import sorting and remove unused import
ptarjan d43a646
Update requirements files
ptarjan 3babc8c
Fix get_id to be method call instead of property
ptarjan 196c372
Update generated files from hassfest
ptarjan 6609001
python3 -m script.hassfest
ptarjan 5594b43
Address reviewer feedback: move device class mapping to platform module
ptarjan 91ad7af
Remove defusedxml from requirements
ptarjan 5079d4a
Use specific exception type in __init__.py
ptarjan 21f0904
Restore original PLATFORM_SCHEMA for YAML compatibility
ptarjan 2c3becf
Convert entity creation to list comprehension
ptarjan 89986f3
Remove unused self._entry in HikvisionBinarySensor
ptarjan 721b507
Use specific exception type in config_flow.py
ptarjan a94f7e0
Remove reauth flow for follow-up PR
ptarjan c6e1dfe
Use CONF_NAME from YAML config for import title
ptarjan 25bcac6
Use homeassistant domain for deprecated_yaml issue
ptarjan 600fd7a
Fix tests for reviewer feedback changes
ptarjan 39f5bc4
Remove incorrect coordinator comment
ptarjan 50fa0fe
Combine mock_hikcamera fixtures and remove unnecessary MagicMock
ptarjan 4b6bc2f
Improve config flow tests per reviewer feedback
ptarjan d1bb6f4
Simplify init tests per reviewer feedback
ptarjan 0dfbfd1
Improve binary sensor tests per reviewer feedback
ptarjan 8a4f84f
Add snapshot tests for binary sensor entities
ptarjan 21eb000
Restore constants to original locations
ptarjan c11fb3f
Achieve 100% test coverage for hikvision integration
ptarjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,87 @@ | ||
| """The hikvision component.""" | ||
| """The Hikvision integration.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| import logging | ||
|
|
||
| from pyhik.hikvision import HikCamera | ||
| import requests | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
| from homeassistant.const import ( | ||
| CONF_HOST, | ||
| CONF_PASSWORD, | ||
| CONF_PORT, | ||
| CONF_SSL, | ||
| CONF_USERNAME, | ||
| Platform, | ||
| ) | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.exceptions import ConfigEntryNotReady | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| PLATFORMS = [Platform.BINARY_SENSOR] | ||
|
|
||
|
|
||
| @dataclass | ||
| class HikvisionData: | ||
| """Data class for Hikvision runtime data.""" | ||
|
|
||
| camera: HikCamera | ||
| device_id: str | ||
| device_name: str | ||
| device_type: str | ||
|
|
||
|
|
||
| type HikvisionConfigEntry = ConfigEntry[HikvisionData] | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: HikvisionConfigEntry) -> bool: | ||
| """Set up Hikvision from a config entry.""" | ||
| host = entry.data[CONF_HOST] | ||
| port = entry.data[CONF_PORT] | ||
| username = entry.data[CONF_USERNAME] | ||
| password = entry.data[CONF_PASSWORD] | ||
| ssl = entry.data[CONF_SSL] | ||
|
|
||
| protocol = "https" if ssl else "http" | ||
| url = f"{protocol}://{host}" | ||
|
|
||
| try: | ||
| camera = await hass.async_add_executor_job( | ||
| HikCamera, url, port, username, password | ||
| ) | ||
| except requests.exceptions.RequestException as err: | ||
| raise ConfigEntryNotReady(f"Unable to connect to {host}") from err | ||
|
|
||
| device_id = camera.get_id() | ||
| if device_id is None: | ||
| raise ConfigEntryNotReady(f"Unable to get device ID from {host}") | ||
|
|
||
| device_name = camera.get_name or host | ||
| device_type = camera.get_type or "Camera" | ||
|
|
||
| entry.runtime_data = HikvisionData( | ||
| camera=camera, | ||
| device_id=device_id, | ||
| device_name=device_name, | ||
| device_type=device_type, | ||
| ) | ||
|
|
||
| # Start the event stream | ||
| await hass.async_add_executor_job(camera.start_stream) | ||
|
|
||
| await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, entry: HikvisionConfigEntry) -> bool: | ||
| """Unload a config entry.""" | ||
| if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): | ||
| # Stop the event stream | ||
| await hass.async_add_executor_job(entry.runtime_data.camera.disconnect) | ||
|
|
||
| return unload_ok | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.