Add Reolink update entity (#87865)
This commit is contained in:
parent
2314d15761
commit
f97b50f762
8 changed files with 162 additions and 34 deletions
|
@ -3,25 +3,69 @@ from __future__ import annotations
|
|||
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
|
||||
from . import ReolinkData
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
class ReolinkCoordinatorEntity(CoordinatorEntity):
|
||||
"""Parent class for Reolink hardware camera entities."""
|
||||
class ReolinkBaseCoordinatorEntity(CoordinatorEntity):
|
||||
"""Parent class for entities that control the Reolink NVR itself, without a channel.
|
||||
|
||||
def __init__(self, reolink_data: ReolinkData, channel: int) -> None:
|
||||
"""Initialize ReolinkCoordinatorEntity for a hardware camera."""
|
||||
coordinator = reolink_data.device_coordinator
|
||||
A camera connected directly to HomeAssistant without using a NVR is in the reolink API
|
||||
basically a NVR with a single channel that has the camera connected to that channel.
|
||||
"""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
reolink_data: ReolinkData,
|
||||
coordinator: DataUpdateCoordinator | None = None,
|
||||
) -> None:
|
||||
"""Initialize ReolinkBaseCoordinatorEntity for a NVR entity without a channel."""
|
||||
if coordinator is None:
|
||||
coordinator = reolink_data.device_coordinator
|
||||
super().__init__(coordinator)
|
||||
|
||||
self._host = reolink_data.host
|
||||
self._channel = channel
|
||||
|
||||
http_s = "https" if self._host.api.use_https else "http"
|
||||
conf_url = f"{http_s}://{self._host.api.host}:{self._host.api.port}"
|
||||
self._conf_url = f"{http_s}://{self._host.api.host}:{self._host.api.port}"
|
||||
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=self._conf_url,
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return self._host.api.session_active and super().available
|
||||
|
||||
|
||||
class ReolinkCoordinatorEntity(ReolinkBaseCoordinatorEntity):
|
||||
"""Parent class for Reolink hardware camera entities connected to a channel of the NVR."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
reolink_data: ReolinkData,
|
||||
channel: int,
|
||||
coordinator: DataUpdateCoordinator | None = None,
|
||||
) -> None:
|
||||
"""Initialize ReolinkCoordinatorEntity for a hardware camera connected to a channel of the NVR."""
|
||||
super().__init__(reolink_data, coordinator)
|
||||
|
||||
self._channel = channel
|
||||
|
||||
if self._host.api.is_nvr:
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, f"{self._host.unique_id}_ch{self._channel}")},
|
||||
|
@ -29,21 +73,5 @@ class ReolinkCoordinatorEntity(CoordinatorEntity):
|
|||
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,
|
||||
configuration_url=self._conf_url,
|
||||
)
|
||||
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,
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return self._host.api.session_active and super().available
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue