Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base entities for the Motionblinds Bluetooth integration."""
2 
3 import logging
4 
5 from motionblindsble.const import MotionBlindType
6 from motionblindsble.device import MotionDevice
7 
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.const import CONF_ADDRESS
10 from homeassistant.helpers.device_registry import CONNECTION_BLUETOOTH, DeviceInfo
11 from homeassistant.helpers.entity import Entity, EntityDescription
12 
13 from .const import CONF_BLIND_TYPE, CONF_MAC_CODE, MANUFACTURER
14 
15 _LOGGER = logging.getLogger(__name__)
16 
17 
19  """Base class for Motionblinds Bluetooth entities."""
20 
21  _attr_has_entity_name = True
22  _attr_should_poll = False
23 
24  device: MotionDevice
25  entry: ConfigEntry
26 
27  def __init__(
28  self,
29  device: MotionDevice,
30  entry: ConfigEntry,
31  entity_description: EntityDescription,
32  unique_id_suffix: str | None = None,
33  ) -> None:
34  """Initialize the entity."""
35  if unique_id_suffix is None:
36  self._attr_unique_id_attr_unique_id = entry.data[CONF_ADDRESS]
37  else:
38  self._attr_unique_id_attr_unique_id = f"{entry.data[CONF_ADDRESS]}_{unique_id_suffix}"
39  self.devicedevice = device
40  self.entryentry = entry
41  self.entity_descriptionentity_description = entity_description
42  self._attr_device_info_attr_device_info = DeviceInfo(
43  connections={(CONNECTION_BLUETOOTH, entry.data[CONF_ADDRESS])},
44  manufacturer=MANUFACTURER,
45  model=MotionBlindType[entry.data[CONF_BLIND_TYPE].upper()].value,
46  name=device.display_name,
47  )
48 
49  async def async_update(self) -> None:
50  """Update state, called by HA if there is a poll interval and by the service homeassistant.update_entity."""
51  _LOGGER.debug("(%s) Updating entity", self.entryentry.data[CONF_MAC_CODE])
52  await self.devicedevice.status_query()
None __init__(self, MotionDevice device, ConfigEntry entry, EntityDescription entity_description, str|None unique_id_suffix=None)
Definition: entity.py:33