2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Verisure binary sensors."""
|
2017-06-26 20:30:25 +00:00
|
|
|
import logging
|
|
|
|
|
2019-11-13 13:12:36 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
DEVICE_CLASS_CONNECTIVITY,
|
2020-04-23 19:57:07 +00:00
|
|
|
BinarySensorEntity,
|
2019-11-13 13:12:36 +00:00
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
|
|
|
from . import CONF_DOOR_WINDOW, 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)):
|
2019-07-31 19:25:30 +00:00
|
|
|
sensors.extend(
|
|
|
|
[
|
|
|
|
VerisureDoorWindowSensor(device_label)
|
|
|
|
for device_label in hub.get(
|
|
|
|
"$.doorWindow.doorWindowDevice[*].deviceLabel"
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
2019-11-13 13:12:36 +00:00
|
|
|
|
|
|
|
sensors.extend([VerisureEthernetStatus()])
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(sensors)
|
2017-06-26 20:30:25 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class VerisureDoorWindowSensor(BinarySensorEntity):
|
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",
|
2019-07-31 19:25:30 +00:00
|
|
|
self._device_label,
|
|
|
|
)
|
2017-06-26 20:30:25 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the state of the sensor."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return (
|
|
|
|
hub.get_first(
|
|
|
|
"$.doorWindow.doorWindowDevice[?(@.deviceLabel=='%s')].state",
|
|
|
|
self._device_label,
|
|
|
|
)
|
|
|
|
== "OPEN"
|
|
|
|
)
|
2017-06-26 20:30:25 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Return True if entity is available."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return (
|
|
|
|
hub.get_first(
|
|
|
|
"$.doorWindow.doorWindowDevice[?(@.deviceLabel=='%s')]",
|
|
|
|
self._device_label,
|
|
|
|
)
|
|
|
|
is not None
|
|
|
|
)
|
2017-06-26 20:30:25 +00:00
|
|
|
|
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()
|
2019-11-13 13:12:36 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class VerisureEthernetStatus(BinarySensorEntity):
|
2019-11-13 13:12:36 +00:00
|
|
|
"""Representation of a Verisure VBOX internet status."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the binary sensor."""
|
|
|
|
return "Verisure Ethernet status"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return hub.get_first("$.ethernetConnectedNow")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Return True if entity is available."""
|
|
|
|
return hub.get_first("$.ethernetConnectedNow") is not None
|
|
|
|
|
|
|
|
# pylint: disable=no-self-use
|
|
|
|
def update(self):
|
|
|
|
"""Update the state of the sensor."""
|
|
|
|
hub.update_overview()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
|
|
return DEVICE_CLASS_CONNECTIVITY
|