core/homeassistant/components/tcp/binary_sensor.py

27 lines
775 B
Python
Raw Normal View History

"""Provides a binary sensor which gets its values from a TCP socket."""
2016-02-14 00:03:56 +00:00
import logging
from homeassistant.components.binary_sensor import BinarySensorDevice
from .sensor import CONF_VALUE_ON, PLATFORM_SCHEMA, TcpSensor
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
def setup_platform(hass, config, add_entities, discovery_info=None):
2016-10-22 04:14:35 +00:00
"""Set up the TCP binary sensor."""
add_entities([TcpBinarySensor(hass, config)])
2016-02-14 00:03:56 +00:00
2016-10-22 04:14:35 +00:00
class TcpBinarySensor(BinarySensorDevice, TcpSensor):
"""A binary sensor which is on when its state == CONF_VALUE_ON."""
2016-03-07 19:21:08 +00:00
required = (CONF_VALUE_ON,)
2016-02-14 00:03:56 +00:00
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self._state == self._config[CONF_VALUE_ON]