2019-02-13 20:21:14 +00:00
|
|
|
"""Support for AlarmDecoder sensors (Shows Panel Display)."""
|
2021-03-22 11:37:16 +00:00
|
|
|
from homeassistant.components.sensor import SensorEntity
|
2020-09-13 17:29:25 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-04-17 10:48:03 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2020-09-13 17:29:25 +00:00
|
|
|
from .const import SIGNAL_PANEL_MESSAGE
|
2017-04-12 09:35:35 +00:00
|
|
|
|
|
|
|
|
2020-09-13 17:29:25 +00:00
|
|
|
async def async_setup_entry(
|
2021-04-17 10:48:03 +00:00
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities
|
2021-07-06 14:18:00 +00:00
|
|
|
) -> bool:
|
2020-09-13 17:29:25 +00:00
|
|
|
"""Set up for AlarmDecoder sensor."""
|
2017-04-12 09:35:35 +00:00
|
|
|
|
2020-09-13 17:29:25 +00:00
|
|
|
entity = AlarmDecoderSensor()
|
|
|
|
async_add_entities([entity])
|
|
|
|
return True
|
2017-04-12 09:35:35 +00:00
|
|
|
|
|
|
|
|
2021-03-22 11:37:16 +00:00
|
|
|
class AlarmDecoderSensor(SensorEntity):
|
2017-04-12 09:35:35 +00:00
|
|
|
"""Representation of an AlarmDecoder keypad."""
|
|
|
|
|
2021-07-06 14:18:00 +00:00
|
|
|
_attr_icon = "mdi:alarm-check"
|
|
|
|
_attr_name = "Alarm Panel Display"
|
|
|
|
_attr_should_poll = False
|
2017-04-12 09:35:35 +00:00
|
|
|
|
2018-10-01 06:55:43 +00:00
|
|
|
async def async_added_to_hass(self):
|
2017-04-12 09:35:35 +00:00
|
|
|
"""Register callbacks."""
|
2020-04-02 16:25:33 +00:00
|
|
|
self.async_on_remove(
|
|
|
|
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
|
|
|
SIGNAL_PANEL_MESSAGE, self._message_callback
|
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2017-04-12 09:35:35 +00:00
|
|
|
|
|
|
|
def _message_callback(self, message):
|
2021-07-06 14:18:00 +00:00
|
|
|
if self._attr_state != message.text:
|
|
|
|
self._attr_state = message.text
|
2017-12-16 23:52:59 +00:00
|
|
|
self.schedule_update_ha_state()
|