2022-12-27 20:15:53 +00:00
|
|
|
"""Reolink parent entity class."""
|
2023-01-01 22:32:17 +00:00
|
|
|
from __future__ import annotations
|
2022-12-27 20:15:53 +00:00
|
|
|
|
|
|
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
|
|
|
from homeassistant.helpers.entity import DeviceInfo
|
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
|
|
|
|
from . import ReolinkData
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
|
|
|
|
class ReolinkCoordinatorEntity(CoordinatorEntity):
|
2023-01-20 21:27:59 +00:00
|
|
|
"""Parent class for Reolink hardware camera entities."""
|
2022-12-27 20:15:53 +00:00
|
|
|
|
2023-01-20 21:27:59 +00:00
|
|
|
def __init__(self, reolink_data: ReolinkData, channel: int) -> None:
|
|
|
|
"""Initialize ReolinkCoordinatorEntity for a hardware camera."""
|
2023-01-01 22:32:17 +00:00
|
|
|
coordinator = reolink_data.device_coordinator
|
2022-12-27 20:15:53 +00:00
|
|
|
super().__init__(coordinator)
|
|
|
|
|
2023-01-01 22:32:17 +00:00
|
|
|
self._host = reolink_data.host
|
|
|
|
self._channel = channel
|
2022-12-27 20:15:53 +00:00
|
|
|
|
|
|
|
http_s = "https" if self._host.api.use_https else "http"
|
|
|
|
conf_url = f"{http_s}://{self._host.api.host}:{self._host.api.port}"
|
2023-01-20 21:27:59 +00:00
|
|
|
if self._host.api.is_nvr:
|
2023-01-01 22:32:17 +00:00
|
|
|
self._attr_device_info = DeviceInfo(
|
2022-12-27 20:15:53 +00:00
|
|
|
identifiers={(DOMAIN, f"{self._host.unique_id}_ch{self._channel}")},
|
|
|
|
via_device=(DOMAIN, self._host.unique_id),
|
|
|
|
name=self._host.api.camera_name(self._channel),
|
|
|
|
model=self._host.api.camera_model(self._channel),
|
|
|
|
manufacturer=self._host.api.manufacturer,
|
|
|
|
configuration_url=conf_url,
|
|
|
|
)
|
2023-01-01 22:32:17 +00:00
|
|
|
else:
|
|
|
|
self._attr_device_info = DeviceInfo(
|
|
|
|
identifiers={(DOMAIN, self._host.unique_id)},
|
|
|
|
connections={(CONNECTION_NETWORK_MAC, self._host.api.mac_address)},
|
|
|
|
name=self._host.api.nvr_name,
|
|
|
|
model=self._host.api.model,
|
|
|
|
manufacturer=self._host.api.manufacturer,
|
|
|
|
hw_version=self._host.api.hardware_version,
|
|
|
|
sw_version=self._host.api.sw_version,
|
|
|
|
configuration_url=conf_url,
|
|
|
|
)
|
2022-12-27 20:15:53 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return True if entity is available."""
|
2023-01-01 22:32:17 +00:00
|
|
|
return self._host.api.session_active and super().available
|