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-10-22 04:14:35 +00:00
|
|
|
from homeassistant.components.sensor.tcp import (
|
|
|
|
TcpSensor, CONF_VALUE_ON, PLATFORM_SCHEMA)
|
2016-02-14 00:03:56 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2016-10-22 04:14:35 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({})
|
2016-02-14 00:03:56 +00:00
|
|
|
|
2016-02-22 09:11:46 +00:00
|
|
|
|
2016-10-22 04:14:35 +00:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
"""Set up the TCP binary sensor."""
|
|
|
|
add_devices([TcpBinarySensor(hass, config)])
|
2016-02-14 00:03:56 +00:00
|
|
|
|
|
|
|
|
2016-10-22 04:14:35 +00:00
|
|
|
class TcpBinarySensor(BinarySensorDevice, TcpSensor):
|
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]
|