Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base class for Acaia entities."""
2 
3 from dataclasses import dataclass
4 
6  CONNECTION_BLUETOOTH,
7  DeviceInfo,
8  format_mac,
9 )
10 from homeassistant.helpers.entity import EntityDescription
11 from homeassistant.helpers.update_coordinator import CoordinatorEntity
12 
13 from .const import DOMAIN
14 from .coordinator import AcaiaCoordinator
15 
16 
17 @dataclass
18 class AcaiaEntity(CoordinatorEntity[AcaiaCoordinator]):
19  """Common elements for all entities."""
20 
21  _attr_has_entity_name = True
22 
23  def __init__(
24  self,
25  coordinator: AcaiaCoordinator,
26  entity_description: EntityDescription,
27  ) -> None:
28  """Initialize the entity."""
29  super().__init__(coordinator)
30  self.entity_descriptionentity_description = entity_description
31  self._scale_scale_scale = coordinator.scale
32  formatted_mac = format_mac(self._scale_scale_scale.mac)
33  self._attr_unique_id_attr_unique_id = f"{formatted_mac}_{entity_description.key}"
34 
35  self._attr_device_info_attr_device_info = DeviceInfo(
36  identifiers={(DOMAIN, formatted_mac)},
37  manufacturer="Acaia",
38  model=self._scale_scale_scale.model,
39  suggested_area="Kitchen",
40  connections={(CONNECTION_BLUETOOTH, self._scale_scale_scale.mac)},
41  )
42 
43  @property
44  def available(self) -> bool:
45  """Returns whether entity is available."""
46  return super().available and self._scale_scale_scale.connected
None __init__(self, AcaiaCoordinator coordinator, EntityDescription entity_description)
Definition: entity.py:27