2019-02-13 20:21:14 +00:00
|
|
|
"""Interfaces with Egardia/Woonveilig alarm control panel."""
|
2018-03-02 11:50:00 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
2019-02-13 20:21:14 +00:00
|
|
|
from homeassistant.const import STATE_OFF, STATE_ON
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import ATTR_DISCOVER_DEVICES, EGARDIA_DEVICE
|
|
|
|
|
2018-03-02 11:50:00 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2019-02-13 20:21:14 +00:00
|
|
|
|
|
|
|
EGARDIA_TYPE_TO_DEVICE_CLASS = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"IR Sensor": "motion",
|
|
|
|
"Door Contact": "opening",
|
|
|
|
"IR": "motion",
|
2019-02-13 20:21:14 +00:00
|
|
|
}
|
2018-03-02 11:50:00 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2018-03-02 11:50:00 +00:00
|
|
|
"""Initialize the platform."""
|
2019-07-31 19:25:30 +00:00
|
|
|
if discovery_info is None or discovery_info[ATTR_DISCOVER_DEVICES] is None:
|
2018-03-02 11:50:00 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
disc_info = discovery_info[ATTR_DISCOVER_DEVICES]
|
2019-02-13 20:21:14 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
async_add_entities(
|
2018-03-02 11:50:00 +00:00
|
|
|
(
|
|
|
|
EgardiaBinarySensor(
|
2019-07-31 19:25:30 +00:00
|
|
|
sensor_id=disc_info[sensor]["id"],
|
|
|
|
name=disc_info[sensor]["name"],
|
2018-03-02 11:50:00 +00:00
|
|
|
egardia_system=hass.data[EGARDIA_DEVICE],
|
|
|
|
device_class=EGARDIA_TYPE_TO_DEVICE_CLASS.get(
|
2019-07-31 19:25:30 +00:00
|
|
|
disc_info[sensor]["type"], None
|
|
|
|
),
|
2018-03-02 11:50:00 +00:00
|
|
|
)
|
|
|
|
for sensor in disc_info
|
2019-07-31 19:25:30 +00:00
|
|
|
),
|
|
|
|
True,
|
|
|
|
)
|
2018-03-02 11:50:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EgardiaBinarySensor(BinarySensorDevice):
|
|
|
|
"""Represents a sensor based on an Egardia sensor (IR, Door Contact)."""
|
|
|
|
|
|
|
|
def __init__(self, sensor_id, name, egardia_system, device_class):
|
|
|
|
"""Initialize the sensor device."""
|
|
|
|
self._id = sensor_id
|
|
|
|
self._name = name
|
|
|
|
self._state = None
|
|
|
|
self._device_class = device_class
|
|
|
|
self._egardia_system = egardia_system
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the status."""
|
|
|
|
egardia_input = self._egardia_system.getsensorstate(self._id)
|
|
|
|
self._state = STATE_ON if egardia_input else STATE_OFF
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2018-08-24 08:28:43 +00:00
|
|
|
"""Return the name of the device."""
|
2018-03-02 11:50:00 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Whether the device is switched on."""
|
|
|
|
return self._state == STATE_ON
|
|
|
|
|
|
|
|
@property
|
|
|
|
def hidden(self):
|
|
|
|
"""Whether the device is hidden by default."""
|
|
|
|
# these type of sensors are probably mainly used for automations
|
|
|
|
return True
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
2018-08-24 08:28:43 +00:00
|
|
|
"""Return the device class."""
|
2018-03-02 11:50:00 +00:00
|
|
|
return self._device_class
|