2019-02-13 21:21:14 +01:00
|
|
|
"""Support for AlarmDecoder sensors (Shows Panel Display)."""
|
2021-03-22 12:37:16 +01:00
|
|
|
from homeassistant.components.sensor import SensorEntity
|
2020-09-13 13:29:25 -04:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-04-17 12:48:03 +02:00
|
|
|
from homeassistant.core import HomeAssistant
|
2019-03-20 22:56:46 -07:00
|
|
|
|
2020-09-13 13:29:25 -04:00
|
|
|
from .const import SIGNAL_PANEL_MESSAGE
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
|
2020-09-13 13:29:25 -04:00
|
|
|
async def async_setup_entry(
|
2021-04-17 12:48:03 +02:00
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities
|
2020-09-13 13:29:25 -04:00
|
|
|
):
|
|
|
|
"""Set up for AlarmDecoder sensor."""
|
2017-04-12 05:35:35 -04:00
|
|
|
|
2020-09-13 13:29:25 -04:00
|
|
|
entity = AlarmDecoderSensor()
|
|
|
|
async_add_entities([entity])
|
|
|
|
return True
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
|
2021-03-22 12:37:16 +01:00
|
|
|
class AlarmDecoderSensor(SensorEntity):
|
2017-04-12 05:35:35 -04:00
|
|
|
"""Representation of an AlarmDecoder keypad."""
|
|
|
|
|
2020-09-13 13:29:25 -04:00
|
|
|
def __init__(self):
|
2017-04-12 05:35:35 -04:00
|
|
|
"""Initialize the alarm panel."""
|
|
|
|
self._display = ""
|
2017-12-16 15:52:59 -08:00
|
|
|
self._state = None
|
2019-07-31 12:25:30 -07:00
|
|
|
self._icon = "mdi:alarm-check"
|
|
|
|
self._name = "Alarm Panel Display"
|
2017-04-12 05:35:35 -04:00
|
|
|
|
2018-10-01 08:55:43 +02:00
|
|
|
async def async_added_to_hass(self):
|
2017-04-12 05:35:35 -04:00
|
|
|
"""Register callbacks."""
|
2020-04-02 09:25:33 -07:00
|
|
|
self.async_on_remove(
|
|
|
|
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
|
|
|
SIGNAL_PANEL_MESSAGE, self._message_callback
|
|
|
|
)
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
def _message_callback(self, message):
|
|
|
|
if self._display != message.text:
|
|
|
|
self._display = message.text
|
2017-12-16 15:52:59 -08:00
|
|
|
self.schedule_update_ha_state()
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the icon if any."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the overall state."""
|
|
|
|
return self._display
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the device."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
"""No polling needed."""
|
|
|
|
return False
|