1 """Reolink parent entity class."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from reolink_aio.api
import DUAL_LENS_MODELS, Chime, Host
15 DataUpdateCoordinator,
18 from .
import ReolinkData
19 from .const
import DOMAIN
22 @dataclass(frozen=True, kw_only=True)
24 """A class that describes entities for Reolink."""
26 cmd_key: str |
None =
None
27 cmd_id: int |
None =
None
30 @dataclass(frozen=True, kw_only=True)
32 """A class that describes entities for a camera channel."""
34 supported: Callable[[Host, int], bool] =
lambda api, ch:
True
37 @dataclass(frozen=True, kw_only=True)
39 """A class that describes host entities."""
41 supported: Callable[[Host], bool] =
lambda api:
True
44 @dataclass(frozen=True, kw_only=True)
46 """A class that describes entities for a chime."""
48 supported: Callable[[Chime], bool] =
lambda chime:
True
52 """Parent class for entities that control the Reolink NVR itself, without a channel.
54 A camera connected directly to HomeAssistant without using a NVR is in the reolink API
55 basically a NVR with a single channel that has the camera connected to that channel.
58 _attr_has_entity_name =
True
59 entity_description: ReolinkEntityDescription
63 reolink_data: ReolinkData,
64 coordinator: DataUpdateCoordinator[
None] |
None =
None,
66 """Initialize ReolinkHostCoordinatorEntity."""
67 if coordinator
is None:
68 coordinator = reolink_data.device_coordinator
71 self.
_host_host = reolink_data.host
72 self.
_attr_unique_id_attr_unique_id = f
"{self._host.unique_id}_{self.entity_description.key}"
74 http_s =
"https" if self.
_host_host.api.use_https
else "http"
75 self.
_conf_url_conf_url = f
"{http_s}://{self._host.api.host}:{self._host.api.port}"
78 identifiers={(DOMAIN, self.
_dev_id_dev_id)},
79 connections={(CONNECTION_NETWORK_MAC, self.
_host_host.api.mac_address)},
80 name=self.
_host_host.api.nvr_name,
81 model=self.
_host_host.api.model,
82 model_id=self.
_host_host.api.item_number,
83 manufacturer=self.
_host_host.api.manufacturer,
84 hw_version=self.
_host_host.api.hardware_version,
85 sw_version=self.
_host_host.api.sw_version,
86 serial_number=self.
_host_host.api.uid,
87 configuration_url=self.
_conf_url_conf_url,
92 """Return True if entity is available."""
93 return self.
_host_host.api.session_active
and super().available
97 """Handle incoming TCP push event."""
98 self.async_write_ha_state()
101 """Register callback for TCP push events."""
102 self.
_host_host.api.baichuan.register_callback(
107 """Entity created."""
109 cmd_key = self.entity_description.cmd_key
110 cmd_id = self.entity_description.cmd_id
111 if cmd_key
is not None:
112 self.
_host_host.async_register_update_cmd(cmd_key)
113 if cmd_id
is not None and self.
_attr_unique_id_attr_unique_id
is not None:
117 """Entity removed."""
118 cmd_key = self.entity_description.cmd_key
119 cmd_id = self.entity_description.cmd_id
120 if cmd_key
is not None:
121 self.
_host_host.async_unregister_update_cmd(cmd_key)
122 if cmd_id
is not None and self.
_attr_unique_id_attr_unique_id
is not None:
128 """Force full update from the generic entity update service."""
129 self.
_host_host.last_wake = 0
134 """Parent class for Reolink hardware camera entities connected to a channel of the NVR."""
138 reolink_data: ReolinkData,
140 coordinator: DataUpdateCoordinator[
None] |
None =
None,
142 """Initialize ReolinkChannelCoordinatorEntity for a hardware camera connected to a channel of the NVR."""
143 super().
__init__(reolink_data, coordinator)
146 if self.
_host_host.api.supported(channel,
"UID"):
150 f
"{self._host.unique_id}_{channel}_{self.entity_description.key}"
154 if self.
_host_host.api.model
in DUAL_LENS_MODELS:
157 if self.
_host_host.api.is_nvr:
158 if self.
_host_host.api.supported(dev_ch,
"UID"):
160 f
"{self._host.unique_id}_{self._host.api.camera_uid(dev_ch)}"
167 via_device=(DOMAIN, self.
_host_host.unique_id),
168 name=self.
_host_host.api.camera_name(dev_ch),
169 model=self.
_host_host.api.camera_model(dev_ch),
170 manufacturer=self.
_host_host.api.manufacturer,
171 hw_version=self.
_host_host.api.camera_hardware_version(dev_ch),
172 sw_version=self.
_host_host.api.camera_sw_version(dev_ch),
173 serial_number=self.
_host_host.api.camera_uid(dev_ch),
174 configuration_url=self.
_conf_url_conf_url,
179 """Return True if entity is available."""
180 return super().available
and self.
_host_host.api.camera_online(self.
_channel_channel)
183 """Register callback for TCP push events."""
184 self.
_host_host.api.baichuan.register_callback(
189 """Entity created."""
191 cmd_key = self.entity_description.cmd_key
192 if cmd_key
is not None:
193 self.
_host_host.async_register_update_cmd(cmd_key, self.
_channel_channel)
196 """Entity removed."""
197 cmd_key = self.entity_description.cmd_key
198 if cmd_key
is not None:
199 self.
_host_host.async_unregister_update_cmd(cmd_key, self.
_channel_channel)
205 """Parent class for Reolink chime entities connected."""
209 reolink_data: ReolinkData,
211 coordinator: DataUpdateCoordinator[
None] |
None =
None,
213 """Initialize ReolinkChimeCoordinatorEntity for a chime."""
214 super().
__init__(reolink_data, chime.channel, coordinator)
219 f
"{self._host.unique_id}_chime{chime.dev_id}_{self.entity_description.key}"
226 via_device=(DOMAIN, cam_dev_id),
228 model=
"Reolink Chime",
229 manufacturer=self.
_host_host.api.manufacturer,
230 serial_number=
str(chime.dev_id),
231 configuration_url=self.
_conf_url_conf_url,
236 """Return True if entity is available."""
237 return self.
_chime_chime.online
and super().available
None async_will_remove_from_hass(self)
None async_added_to_hass(self)
None __init__(self, ReolinkData reolink_data, int channel, DataUpdateCoordinator[None]|None coordinator=None)
None register_callback(self, str unique_id, int cmd_id)
None __init__(self, ReolinkData reolink_data, Chime chime, DataUpdateCoordinator[None]|None coordinator=None)
None async_will_remove_from_hass(self)
None register_callback(self, str unique_id, int cmd_id)
None async_added_to_hass(self)
None __init__(self, ReolinkData reolink_data, DataUpdateCoordinator[None]|None coordinator=None)
None _push_callback(self)