Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Entity representing a Skybell HD Doorbell."""
2 
3 from __future__ import annotations
4 
5 from aioskybell import SkybellDevice
6 
7 from homeassistant.const import ATTR_CONNECTIONS
8 from homeassistant.helpers import device_registry as dr
9 from homeassistant.helpers.device_registry import DeviceInfo
10 from homeassistant.helpers.entity import EntityDescription
11 from homeassistant.helpers.update_coordinator import CoordinatorEntity
12 
13 from .const import DEFAULT_NAME, DOMAIN
14 from .coordinator import SkybellDataUpdateCoordinator
15 
16 
17 class SkybellEntity(CoordinatorEntity[SkybellDataUpdateCoordinator]):
18  """An HA implementation for Skybell entity."""
19 
20  _attr_attribution = "Data provided by Skybell.com"
21  _attr_has_entity_name = True
22 
23  def __init__(
24  self, coordinator: SkybellDataUpdateCoordinator, description: EntityDescription
25  ) -> None:
26  """Initialize a SkyBell entity."""
27  super().__init__(coordinator)
28  self.entity_descriptionentity_description = description
29  self._attr_unique_id_attr_unique_id = f"{self._device.device_id}_{description.key}"
30  self._attr_device_info_attr_device_info = DeviceInfo(
31  identifiers={(DOMAIN, self._device_device.device_id)},
32  manufacturer=DEFAULT_NAME,
33  model=self._device_device.type,
34  name=self._device_device.name.capitalize(),
35  sw_version=self._device_device.firmware_ver,
36  )
37  if self._device_device.mac:
38  self._attr_device_info_attr_device_info[ATTR_CONNECTIONS] = {
39  (dr.CONNECTION_NETWORK_MAC, self._device_device.mac)
40  }
41 
42  @property
43  def _device(self) -> SkybellDevice:
44  """Return the device."""
45  return self.coordinator.device
46 
47  async def async_added_to_hass(self) -> None:
48  """When entity is added to hass."""
49  await super().async_added_to_hass()
50  self._handle_coordinator_update()
None __init__(self, SkybellDataUpdateCoordinator coordinator, EntityDescription description)
Definition: entity.py:25