Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Support for AlarmDecoder sensors (Shows Panel Display)."""
2 
3 from homeassistant.components.sensor import SensorEntity
4 from homeassistant.core import HomeAssistant
5 from homeassistant.helpers.dispatcher import async_dispatcher_connect
6 from homeassistant.helpers.entity_platform import AddEntitiesCallback
7 
8 from . import AlarmDecoderConfigEntry
9 from .const import SIGNAL_PANEL_MESSAGE
10 from .entity import AlarmDecoderEntity
11 
12 
14  hass: HomeAssistant,
15  entry: AlarmDecoderConfigEntry,
16  async_add_entities: AddEntitiesCallback,
17 ) -> None:
18  """Set up for AlarmDecoder sensor."""
19 
20  entity = AlarmDecoderSensor(client=entry.runtime_data.client)
21  async_add_entities([entity])
22 
23 
25  """Representation of an AlarmDecoder keypad."""
26 
27  _attr_translation_key = "alarm_panel_display"
28  _attr_name = "Alarm Panel Display"
29  _attr_should_poll = False
30 
31  def __init__(self, client):
32  """Initialize the alarm decoder sensor."""
33  super().__init__(client)
34  self._attr_unique_id_attr_unique_id = f"{client.serial_number}-display"
35 
36  async def async_added_to_hass(self) -> None:
37  """Register callbacks."""
38  self.async_on_removeasync_on_remove(
40  self.hasshass, SIGNAL_PANEL_MESSAGE, self._message_callback_message_callback
41  )
42  )
43 
44  def _message_callback(self, message):
45  if self._attr_native_value_attr_native_value != message.text:
46  self._attr_native_value_attr_native_value = message.text
47  self.schedule_update_ha_stateschedule_update_ha_state()
None async_on_remove(self, CALLBACK_TYPE func)
Definition: entity.py:1331
None schedule_update_ha_state(self, bool force_refresh=False)
Definition: entity.py:1244
None async_setup_entry(HomeAssistant hass, AlarmDecoderConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: sensor.py:17
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103