2019-02-13 20:21:14 +00:00
|
|
|
"""Support for AlarmDecoder sensors (Shows Panel Display)."""
|
2017-04-12 09:35:35 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.helpers.entity import Entity
|
2019-03-21 05:56:46 +00:00
|
|
|
|
|
|
|
from . import SIGNAL_PANEL_MESSAGE
|
2017-04-12 09:35:35 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up for AlarmDecoder sensor devices."""
|
2017-12-16 23:52:59 +00:00
|
|
|
_LOGGER.debug("AlarmDecoderSensor: setup_platform")
|
2017-04-12 09:35:35 +00:00
|
|
|
|
|
|
|
device = AlarmDecoderSensor(hass)
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities([device])
|
2017-04-12 09:35:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AlarmDecoderSensor(Entity):
|
|
|
|
"""Representation of an AlarmDecoder keypad."""
|
|
|
|
|
|
|
|
def __init__(self, hass):
|
|
|
|
"""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
|