Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base entity for the BleBox devices integration."""
2 
3 import logging
4 
5 from blebox_uniapi.error import Error
6 from blebox_uniapi.feature import Feature
7 
8 from homeassistant.helpers.device_registry import DeviceInfo
9 from homeassistant.helpers.entity import Entity
10 
11 from .const import DOMAIN
12 
13 _LOGGER = logging.getLogger(__name__)
14 
15 
16 class BleBoxEntity[_FeatureT: Feature](Entity):
17  """Implements a common class for entities representing a BleBox feature."""
18 
19  def __init__(self, feature: _FeatureT) -> None:
20  """Initialize a BleBox entity."""
21  self._feature = feature
22  self._attr_name = feature.full_name
23  self._attr_unique_id = feature.unique_id
24  product = feature.product
25  self._attr_device_info = DeviceInfo(
26  identifiers={(DOMAIN, product.unique_id)},
27  manufacturer=product.brand,
28  model=product.model,
29  name=product.name,
30  sw_version=product.firmware_version,
31  configuration_url=f"http://{product.address}",
32  )
33 
34  async def async_update(self) -> None:
35  """Update the entity state."""
36  try:
37  await self._feature.async_update()
38  except Error as ex:
39  _LOGGER.error("Updating '%s' failed: %s", self.name, ex)
None __init__(self, _FeatureT feature)
Definition: entity.py:19