2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Verisure binary sensors."""
|
2017-06-26 20:30:25 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
|
|
|
from homeassistant.components.verisure import CONF_DOOR_WINDOW
|
2018-01-21 06:35:38 +00:00
|
|
|
from homeassistant.components.verisure import HUB as hub
|
2017-06-26 20:30:25 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Set up the Verisure binary sensors."""
|
2017-06-26 20:30:25 +00:00
|
|
|
sensors = []
|
|
|
|
hub.update_overview()
|
|
|
|
|
|
|
|
if int(hub.config.get(CONF_DOOR_WINDOW, 1)):
|
|
|
|
sensors.extend([
|
|
|
|
VerisureDoorWindowSensor(device_label)
|
|
|
|
for device_label in hub.get(
|
|
|
|
"$.doorWindow.doorWindowDevice[*].deviceLabel")])
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(sensors)
|
2017-06-26 20:30:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VerisureDoorWindowSensor(BinarySensorDevice):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Representation of a Verisure door window sensor."""
|
2017-06-26 20:30:25 +00:00
|
|
|
|
|
|
|
def __init__(self, device_label):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Initialize the Verisure door window sensor."""
|
2017-06-26 20:30:25 +00:00
|
|
|
self._device_label = device_label
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the binary sensor."""
|
|
|
|
return hub.get_first(
|
|
|
|
"$.doorWindow.doorWindowDevice[?(@.deviceLabel=='%s')].area",
|
2017-06-30 06:53:14 +00:00
|
|
|
self._device_label)
|
2017-06-26 20:30:25 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return hub.get_first(
|
|
|
|
"$.doorWindow.doorWindowDevice[?(@.deviceLabel=='%s')].state",
|
|
|
|
self._device_label) == "OPEN"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Return True if entity is available."""
|
|
|
|
return hub.get_first(
|
|
|
|
"$.doorWindow.doorWindowDevice[?(@.deviceLabel=='%s')]",
|
|
|
|
self._device_label) is not None
|
|
|
|
|
2018-06-07 19:31:21 +00:00
|
|
|
# pylint: disable=no-self-use
|
2017-06-26 20:30:25 +00:00
|
|
|
def update(self):
|
|
|
|
"""Update the state of the sensor."""
|
|
|
|
hub.update_overview()
|