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
|
2022-03-24 13:19:11 +01:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2022-01-07 16:24:13 +01:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
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(
|
2022-01-07 16:24:13 +01:00
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
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])
|
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."""
|
|
|
|
|
2021-07-06 10:18:00 -04:00
|
|
|
_attr_icon = "mdi:alarm-check"
|
|
|
|
_attr_name = "Alarm Panel Display"
|
|
|
|
_attr_should_poll = False
|
2017-04-12 05:35:35 -04:00
|
|
|
|
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."""
|
2020-04-02 09:25:33 -07:00
|
|
|
self.async_on_remove(
|
2022-03-24 13:19:11 +01:00
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass, SIGNAL_PANEL_MESSAGE, self._message_callback
|
2020-04-02 09:25:33 -07:00
|
|
|
)
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2017-04-12 05:35:35 -04:00
|
|
|
|
|
|
|
def _message_callback(self, message):
|
2021-08-11 10:45:05 +02:00
|
|
|
if self._attr_native_value != message.text:
|
|
|
|
self._attr_native_value = message.text
|
2017-12-16 15:52:59 -08:00
|
|
|
self.schedule_update_ha_state()
|