Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Representation of an EnOcean device."""
2 
3 from enocean.protocol.packet import Packet
4 from enocean.utils import combine_hex
5 
6 from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
7 from homeassistant.helpers.entity import Entity
8 
9 from .const import SIGNAL_RECEIVE_MESSAGE, SIGNAL_SEND_MESSAGE
10 
11 
13  """Parent class for all entities associated with the EnOcean component."""
14 
15  def __init__(self, dev_id: list[int]) -> None:
16  """Initialize the device."""
17  self.dev_iddev_id = dev_id
18 
19  async def async_added_to_hass(self):
20  """Register callbacks."""
21  self.async_on_removeasync_on_remove(
23  self.hasshass, SIGNAL_RECEIVE_MESSAGE, self._message_received_callback_message_received_callback
24  )
25  )
26 
27  def _message_received_callback(self, packet):
28  """Handle incoming packets."""
29 
30  if packet.sender_int == combine_hex(self.dev_iddev_id):
31  self.value_changedvalue_changed(packet)
32 
33  def value_changed(self, packet):
34  """Update the internal state of the device when a packet arrives."""
35 
36  def send_command(self, data, optional, packet_type):
37  """Send a command via the EnOcean dongle."""
38 
39  packet = Packet(packet_type, data=data, optional=optional)
40  dispatcher_send(self.hass, SIGNAL_SEND_MESSAGE, packet)
def send_command(self, data, optional, packet_type)
Definition: entity.py:36
None async_on_remove(self, CALLBACK_TYPE func)
Definition: entity.py:1331
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103
None dispatcher_send(HomeAssistant hass, str signal, *Any args)
Definition: dispatcher.py:137