hass-core/homeassistant/components/tcp/binary_sensor.py
Erik Montnemery b022e08db9
Rename BinarySensorDevice to BinarySensorEntity (#34462)
* Rename BinarySensorDevice to BinarySensorEntity

* Tweak

* Move deprecation warning to __new__, add test

* Move deprecation warning back to __init__

* Move deprecation warning to __init_subclass
2020-04-23 21:57:07 +02:00

26 lines
775 B
Python

"""Provides a binary sensor which gets its values from a TCP socket."""
import logging
from homeassistant.components.binary_sensor import BinarySensorEntity
from .sensor import CONF_VALUE_ON, PLATFORM_SCHEMA, TcpSensor
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({})
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the TCP binary sensor."""
add_entities([TcpBinarySensor(hass, config)])
class TcpBinarySensor(BinarySensorEntity, TcpSensor):
"""A binary sensor which is on when its state == CONF_VALUE_ON."""
required = (CONF_VALUE_ON,)
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self._state == self._config[CONF_VALUE_ON]