Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Support for TCP socket based sensors."""
2 
3 from __future__ import annotations
4 
5 from typing import Final
6 
8  PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA,
9  SensorEntity,
10 )
11 from homeassistant.const import CONF_UNIT_OF_MEASUREMENT
12 from homeassistant.core import HomeAssistant
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
15 
16 from .common import TCP_PLATFORM_SCHEMA
17 from .entity import TcpEntity
18 
19 PLATFORM_SCHEMA: Final = 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 Sensor."""
29  add_entities([TcpSensor(hass, config)])
30 
31 
33  """Implementation of a TCP socket based sensor."""
34 
35  @property
36  def native_value(self) -> StateType:
37  """Return the state of the device."""
38  return self._state_state
39 
40  @property
41  def native_unit_of_measurement(self) -> str | None:
42  """Return the unit of measurement of this entity."""
43  return self._config[CONF_UNIT_OF_MEASUREMENT]
def add_entities(account, async_add_entities, tracked)
Definition: sensor.py:40
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
Definition: sensor.py:27