Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base class for Airtouch5 entities."""
2 
3 from airtouch5py.airtouch5_client import Airtouch5ConnectionStateChange
4 from airtouch5py.airtouch5_simple_client import Airtouch5SimpleClient
5 
6 from homeassistant.core import callback
7 from homeassistant.helpers.entity import Entity
8 
9 
11  """Base class for Airtouch5 entities."""
12 
13  _attr_should_poll = False
14  _attr_has_entity_name = True
15 
16  def __init__(self, client: Airtouch5SimpleClient) -> None:
17  """Initialise the Entity."""
18  self._client_client = client
19  self._attr_available_attr_available = True
20 
21  @callback
23  self, state: Airtouch5ConnectionStateChange
24  ) -> None:
25  self._attr_available_attr_available = state is Airtouch5ConnectionStateChange.CONNECTED
26  self.async_write_ha_stateasync_write_ha_state()
27 
28  async def async_added_to_hass(self) -> None:
29  """Add data updated listener after this object has been initialized."""
30  self._client_client.connection_state_callbacks.append(
31  self._receive_connection_callback_receive_connection_callback
32  )
33 
34  async def async_will_remove_from_hass(self) -> None:
35  """Remove data updated listener when entity is removed from homeassistant."""
36  self._client_client.connection_state_callbacks.remove(
37  self._receive_connection_callback_receive_connection_callback
38  )
None _receive_connection_callback(self, Airtouch5ConnectionStateChange state)
Definition: entity.py:24
None __init__(self, Airtouch5SimpleClient client)
Definition: entity.py:16