Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Provides a binary sensor which gets its values from a TCP socket."""
2 
3 from __future__ import annotations
4 
5 from typing import Final
6 
8  PLATFORM_SCHEMA as BINARY_SENSOR_PLATFORM_SCHEMA,
9  BinarySensorEntity,
10 )
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
14 
15 from .common import TCP_PLATFORM_SCHEMA
16 from .const import CONF_VALUE_ON
17 from .entity import TcpEntity
18 
19 PLATFORM_SCHEMA: Final = BINARY_SENSOR_PLATFORM_SCHEMA.extend(TCP_PLATFORM_SCHEMA)
20 
21 
23  hass: HomeAssistant,
24  config: ConfigType,
25  add_entities: AddEntitiesCallback,
26  discovery_info: DiscoveryInfoType | None = None,
27 ) -> None:
28  """Set up the TCP binary sensor."""
29  add_entities([TcpBinarySensor(hass, config)])
30 
31 
33  """A binary sensor which is on when its state == CONF_VALUE_ON."""
34 
35  @property
36  def is_on(self) -> bool:
37  """Return true if the binary sensor is on."""
38  return self._state_state_state == self._config[CONF_VALUE_ON]
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)