2016-02-14 00:03:56 +00:00
|
|
|
"""
|
2016-02-22 13:43:12 +00:00
|
|
|
Provides a binary sensor which gets its values from a TCP socket.
|
2016-02-22 09:11:46 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/binary_sensor.tcp/
|
2016-02-14 00:03:56 +00:00
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
2016-03-26 17:33:18 +00:00
|
|
|
from homeassistant.components.sensor.tcp import Sensor, CONF_VALUE_ON
|
|
|
|
|
2016-02-14 00:03:56 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2016-02-22 09:11:46 +00:00
|
|
|
"""Create the binary sensor."""
|
2016-02-14 00:03:56 +00:00
|
|
|
if not BinarySensor.validate_config(config):
|
|
|
|
return False
|
2016-02-22 09:11:46 +00:00
|
|
|
|
2016-02-17 18:12:36 +00:00
|
|
|
add_entities((BinarySensor(hass, config),))
|
2016-02-14 00:03:56 +00:00
|
|
|
|
|
|
|
|
2016-02-18 16:57:32 +00:00
|
|
|
class BinarySensor(BinarySensorDevice, Sensor):
|
2016-02-22 09:11:46 +00:00
|
|
|
"""A binary sensor which is on when its state == CONF_VALUE_ON."""
|
2016-03-07 19:21:08 +00:00
|
|
|
|
2016-02-17 17:26:53 +00:00
|
|
|
required = (CONF_VALUE_ON,)
|
2016-02-14 00:03:56 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-02-22 09:11:46 +00:00
|
|
|
"""True if the binary sensor is on."""
|
2016-02-17 17:26:53 +00:00
|
|
|
return self._state == self._config[CONF_VALUE_ON]
|