2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Envisalink sensors (shows panel info)."""
|
2022-01-16 21:34:05 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
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
|
2022-01-16 21:34:05 +00:00
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2017-02-23 21:02:56 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2022-01-16 21:34:05 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
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__)
|
|
|
|
|
|
|
|
|
2022-01-16 21:34:05 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2022-01-26 03:21:58 +00:00
|
|
|
"""Perform the setup for Envisalink sensor entities."""
|
2022-01-16 21:34:05 +00:00
|
|
|
if not discovery_info:
|
|
|
|
return
|
2019-07-31 19:25:30 +00:00
|
|
|
configured_partitions = discovery_info["partitions"]
|
2017-02-23 21:02:56 +00:00
|
|
|
|
2022-01-26 03:21:58 +00:00
|
|
|
entities = []
|
2017-02-23 21:02:56 +00:00
|
|
|
for part_num in configured_partitions:
|
2022-01-26 03:21:58 +00:00
|
|
|
entity_config_data = PARTITION_SCHEMA(configured_partitions[part_num])
|
|
|
|
entity = EnvisalinkSensor(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass,
|
2022-01-26 03:21:58 +00:00
|
|
|
entity_config_data[CONF_PARTITIONNAME],
|
2019-07-31 19:25:30 +00:00
|
|
|
part_num,
|
|
|
|
hass.data[DATA_EVL].alarm_state["partition"][part_num],
|
|
|
|
hass.data[DATA_EVL],
|
|
|
|
)
|
2019-02-13 20:21:14 +00:00
|
|
|
|
2022-01-26 03:21:58 +00:00
|
|
|
entities.append(entity)
|
2017-02-23 21:02:56 +00:00
|
|
|
|
2022-01-26 03:21:58 +00:00
|
|
|
async_add_entities(entities)
|
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
|
|
|
|
2022-08-20 05:52:55 +00:00
|
|
|
async def async_added_to_hass(self) -> None:
|
2017-03-02 09:20:57 +00:00
|
|
|
"""Register callbacks."""
|
2022-01-26 03:21:58 +00:00
|
|
|
self.async_on_remove(
|
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass, SIGNAL_KEYPAD_UPDATE, self.async_update_callback
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.async_on_remove(
|
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass, SIGNAL_PARTITION_UPDATE, self.async_update_callback
|
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2016-06-19 17:45:07 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the icon if any."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
2021-08-11 16:57:12 +00:00
|
|
|
def native_value(self):
|
2016-06-19 17:45:07 +00:00
|
|
|
"""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
|
2022-01-26 03:21:58 +00:00
|
|
|
def async_update_callback(self, partition):
|
2016-06-19 17:45:07 +00:00
|
|
|
"""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()
|