2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Envisalink sensors (shows panel info)."""
|
2016-06-19 17:45:07 +00:00
|
|
|
import logging
|
2017-02-23 21:02:56 +00:00
|
|
|
|
2021-03-22 11:52:29 +00:00
|
|
|
from homeassistant.components.sensor import SensorEntity
|
2017-02-23 21:02:56 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2016-06-19 17:45:07 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import (
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_PARTITIONNAME,
|
|
|
|
DATA_EVL,
|
|
|
|
PARTITION_SCHEMA,
|
|
|
|
SIGNAL_KEYPAD_UPDATE,
|
|
|
|
SIGNAL_PARTITION_UPDATE,
|
|
|
|
EnvisalinkDevice,
|
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2016-06-19 17:45:07 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2016-06-19 17:45:07 +00:00
|
|
|
"""Perform the setup for Envisalink sensor devices."""
|
2019-07-31 19:25:30 +00:00
|
|
|
configured_partitions = discovery_info["partitions"]
|
2017-02-23 21:02:56 +00:00
|
|
|
|
|
|
|
devices = []
|
|
|
|
for part_num in configured_partitions:
|
|
|
|
device_config_data = PARTITION_SCHEMA(configured_partitions[part_num])
|
|
|
|
device = EnvisalinkSensor(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass,
|
|
|
|
device_config_data[CONF_PARTITIONNAME],
|
|
|
|
part_num,
|
|
|
|
hass.data[DATA_EVL].alarm_state["partition"][part_num],
|
|
|
|
hass.data[DATA_EVL],
|
|
|
|
)
|
2019-02-13 20:21:14 +00:00
|
|
|
|
2017-02-23 21:02:56 +00:00
|
|
|
devices.append(device)
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
async_add_entities(devices)
|
2016-06-19 17:45:07 +00:00
|
|
|
|
|
|
|
|
2021-03-22 19:05:13 +00:00
|
|
|
class EnvisalinkSensor(EnvisalinkDevice, SensorEntity):
|
2016-07-01 19:39:30 +00:00
|
|
|
"""Representation of an Envisalink keypad."""
|
2016-06-19 17:45:07 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
def __init__(self, hass, partition_name, partition_number, info, controller):
|
2016-06-19 17:45:07 +00:00
|
|
|
"""Initialize the sensor."""
|
2019-07-31 19:25:30 +00:00
|
|
|
self._icon = "mdi:alarm"
|
2016-06-19 17:45:07 +00:00
|
|
|
self._partition_number = partition_number
|
2017-02-23 21:02:56 +00:00
|
|
|
|
2017-05-02 16:18:47 +00:00
|
|
|
_LOGGER.debug("Setting up sensor for partition: %s", partition_name)
|
2020-04-05 14:01:41 +00:00
|
|
|
super().__init__(f"{partition_name} Keypad", info, controller)
|
2017-02-23 21:02:56 +00:00
|
|
|
|
2018-10-01 06:55:43 +00:00
|
|
|
async def async_added_to_hass(self):
|
2017-03-02 09:20:57 +00:00
|
|
|
"""Register callbacks."""
|
2019-07-31 19:25:30 +00:00
|
|
|
async_dispatcher_connect(self.hass, SIGNAL_KEYPAD_UPDATE, self._update_callback)
|
2017-02-23 21:02:56 +00:00
|
|
|
async_dispatcher_connect(
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass, SIGNAL_PARTITION_UPDATE, self._update_callback
|
|
|
|
)
|
2016-06-19 17:45:07 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the icon if any."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the overall state."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return self._info["status"]["alpha"]
|
2016-06-19 17:45:07 +00:00
|
|
|
|
|
|
|
@property
|
2021-03-11 15:51:03 +00:00
|
|
|
def extra_state_attributes(self):
|
2016-06-19 17:45:07 +00:00
|
|
|
"""Return the state attributes."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return self._info["status"]
|
2016-06-19 17:45:07 +00:00
|
|
|
|
2017-02-23 21:02:56 +00:00
|
|
|
@callback
|
2016-06-19 17:45:07 +00:00
|
|
|
def _update_callback(self, partition):
|
|
|
|
"""Update the partition state in HA, if needed."""
|
|
|
|
if partition is None or int(partition) == self._partition_number:
|
2020-04-01 21:19:51 +00:00
|
|
|
self.async_write_ha_state()
|