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
|
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."""
|
|
|
|
|
2020-09-13 17:29:25 +00:00
|
|
|
def __init__(self):
|
2017-04-12 09:35:35 +00:00
|
|
|
"""Initialize the alarm panel."""
|
|
|
|
self._display = ""
|
2017-12-16 23:52:59 +00:00
|
|
|
self._state = None
|
2019-07-31 19:25:30 +00:00
|
|
|
self._icon = "mdi:alarm-check"
|
|
|
|
self._name = "Alarm Panel Display"
|
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):
|
|
|
|
if self._display != message.text:
|
|
|
|
self._display = message.text
|
2017-12-16 23:52:59 +00:00
|
|
|
self.schedule_update_ha_state()
|
2017-04-12 09:35:35 +00: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
|