Files
homeassistant-core/homeassistant/components/alarmdecoder/sensor.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.5 KiB
Python
Raw Normal View History

2019-02-13 21:21:14 +01:00
"""Support for AlarmDecoder sensors (Shows Panel Display)."""
from homeassistant.components.sensor import SensorEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect
2022-01-07 16:24:13 +01:00
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AlarmDecoderConfigEntry
from .const import SIGNAL_PANEL_MESSAGE
2024-05-17 23:59:44 -07:00
from .entity import AlarmDecoderEntity
2017-04-12 05:35:35 -04:00
2020-09-13 13:29:25 -04:00
async def async_setup_entry(
hass: HomeAssistant,
entry: AlarmDecoderConfigEntry,
async_add_entities: AddEntitiesCallback,
2022-01-07 16:24:13 +01:00
) -> None:
2020-09-13 13:29:25 -04:00
"""Set up for AlarmDecoder sensor."""
2017-04-12 05:35:35 -04:00
entity = AlarmDecoderSensor(client=entry.runtime_data.client)
2020-09-13 13:29:25 -04:00
async_add_entities([entity])
2017-04-12 05:35:35 -04:00
2024-05-17 23:59:44 -07:00
class AlarmDecoderSensor(AlarmDecoderEntity, SensorEntity):
2017-04-12 05:35:35 -04:00
"""Representation of an AlarmDecoder keypad."""
_attr_translation_key = "alarm_panel_display"
2021-07-06 10:18:00 -04:00
_attr_name = "Alarm Panel Display"
_attr_should_poll = False
2017-04-12 05:35:35 -04:00
2024-05-17 23:59:44 -07:00
def __init__(self, client):
"""Initialize the alarm decoder sensor."""
super().__init__(client)
self._attr_unique_id = f"{client.serial_number}-display"
2022-08-18 15:56:52 +02:00
async def async_added_to_hass(self) -> None:
2017-04-12 05:35:35 -04:00
"""Register callbacks."""
self.async_on_remove(
async_dispatcher_connect(
self.hass, SIGNAL_PANEL_MESSAGE, self._message_callback
)
)
2017-04-12 05:35:35 -04:00
def _message_callback(self, message):
if self._attr_native_value != message.text:
self._attr_native_value = message.text
self.schedule_update_ha_state()