mirror of
https://github.com/home-assistant/core.git
synced 2026-08-14 09:13:06 +01:00
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
"""Base entity for Hikvision integration."""
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import device_registry as dr
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
from . import HikvisionConfigEntry
|
|
from .const import DOMAIN
|
|
|
|
|
|
class HikvisionEntity(Entity):
|
|
"""Base class for Hikvision entities."""
|
|
|
|
_attr_has_entity_name = True
|
|
|
|
def __init__(
|
|
self,
|
|
hass: HomeAssistant,
|
|
entry: HikvisionConfigEntry,
|
|
channel: int,
|
|
) -> None:
|
|
"""Initialize the entity."""
|
|
super().__init__()
|
|
self._data = entry.runtime_data
|
|
self._camera = self._data.camera
|
|
self._channel = channel
|
|
|
|
if self._data.device_type == "NVR":
|
|
# NVR channels get their own device linked to the NVR via via_device_id
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={(DOMAIN, f"{self._data.device_id}_{channel}")},
|
|
via_device_id=dr.async_get_device_id_by_identifier(
|
|
hass, (DOMAIN, self._data.device_id), config_entry_id=entry.entry_id
|
|
),
|
|
translation_key="nvr_channel",
|
|
translation_placeholders={
|
|
"device_name": self._data.device_name,
|
|
"channel_number": str(channel),
|
|
},
|
|
manufacturer="Hikvision",
|
|
model="NVR channel",
|
|
)
|
|
else:
|
|
# Single camera device
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={(DOMAIN, self._data.device_id)},
|
|
name=self._data.device_name,
|
|
manufacturer="Hikvision",
|
|
model=self._data.device_type,
|
|
)
|