2016-02-20 22:24:45 +02:00
|
|
|
"""
|
|
|
|
Interfaces with Z-Wave sensors.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation
|
2016-02-22 10:11:46 +01:00
|
|
|
https://home-assistant.io/components/binary_sensor.zwave/
|
2016-02-20 22:24:45 +02:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.zwave import (
|
|
|
|
ATTR_NODE_ID, ATTR_VALUE_ID,
|
|
|
|
COMMAND_CLASS_SENSOR_BINARY, NETWORK,
|
|
|
|
ZWaveDeviceEntity)
|
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
DOMAIN,
|
|
|
|
BinarySensorDevice)
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
DEPENDENCIES = []
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2016-02-22 10:11:46 +01:00
|
|
|
"""Setup the Z-Wave platform for sensors."""
|
2016-02-20 22:24:45 +02:00
|
|
|
|
|
|
|
if discovery_info is None or NETWORK is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
node = NETWORK.nodes[discovery_info[ATTR_NODE_ID]]
|
|
|
|
value = node.values[discovery_info[ATTR_VALUE_ID]]
|
|
|
|
|
|
|
|
value.set_change_verified(False)
|
|
|
|
if value.command_class == COMMAND_CLASS_SENSOR_BINARY:
|
|
|
|
add_devices([ZWaveBinarySensor(value, "opening")])
|
|
|
|
|
|
|
|
|
|
|
|
class ZWaveBinarySensor(BinarySensorDevice, ZWaveDeviceEntity):
|
2016-02-22 10:11:46 +01:00
|
|
|
"""Represents a binary sensor within Z-Wave."""
|
2016-02-20 22:24:45 +02:00
|
|
|
|
|
|
|
def __init__(self, value, sensor_class):
|
|
|
|
self._sensor_type = sensor_class
|
2016-02-21 10:01:03 +02:00
|
|
|
# pylint: disable=import-error
|
2016-02-20 22:24:45 +02:00
|
|
|
from openzwave.network import ZWaveNetwork
|
|
|
|
from pydispatch import dispatcher
|
|
|
|
|
|
|
|
ZWaveDeviceEntity.__init__(self, value, DOMAIN)
|
|
|
|
|
|
|
|
dispatcher.connect(
|
|
|
|
self.value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return True if the binary sensor is on."""
|
|
|
|
return self._value.data
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sensor_class(self):
|
|
|
|
"""Return the class of this sensor, from SENSOR_CLASSES."""
|
|
|
|
return self._sensor_type
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
2016-02-22 10:11:46 +01:00
|
|
|
"""No polling needed."""
|
2016-02-20 22:24:45 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
def value_changed(self, value):
|
2016-02-22 10:11:46 +01:00
|
|
|
"""Called when a value has changed on the network."""
|
2016-02-20 22:24:45 +02:00
|
|
|
if self._value.value_id == value.value_id:
|
|
|
|
self.update_ha_state()
|