Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Arve base entity."""
2 
3 from __future__ import annotations
4 
5 from asyncarve import ArveDeviceInfo
6 
7 from homeassistant.helpers.device_registry import DeviceInfo
8 from homeassistant.helpers.entity import EntityDescription
9 from homeassistant.helpers.update_coordinator import CoordinatorEntity
10 
11 from .const import DOMAIN
12 from .coordinator import ArveCoordinator
13 
14 
15 class ArveDeviceEntity(CoordinatorEntity[ArveCoordinator]):
16  """Defines a base Arve device entity."""
17 
18  _attr_has_entity_name = True
19 
20  def __init__(
21  self,
22  coordinator: ArveCoordinator,
23  description: EntityDescription,
24  serial_number: str,
25  ) -> None:
26  """Initialize the Arve device entity."""
27  super().__init__(coordinator)
28 
29  self.device_serial_numberdevice_serial_number = serial_number
30 
31  self.entity_descriptionentity_description = description
32 
33  self._attr_unique_id_attr_unique_id = f"{serial_number}_{description.key}"
34 
35  self._attr_device_info_attr_device_info = DeviceInfo(
36  identifiers={(DOMAIN, serial_number)},
37  manufacturer="Calanda Air AG",
38  model="Arve Sens Pro",
39  serial_number=serial_number,
40  name=self.devicedevice.info.name,
41  )
42 
43  @property
44  def available(self) -> bool:
45  """Check if device is available."""
46  return super()._attr_available and (
47  self.device_serial_numberdevice_serial_number in self.coordinator.data
48  )
49 
50  @property
51  def device(self) -> ArveDeviceInfo:
52  """Returns device instance."""
53  return self.coordinator.data[self.device_serial_numberdevice_serial_number]
None __init__(self, ArveCoordinator coordinator, EntityDescription description, str serial_number)
Definition: entity.py:25