Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Support for XS1 sensors."""
2 
3 from __future__ import annotations
4 
5 from xs1_api_client.api_constants import ActuatorType
6 
7 from homeassistant.components.sensor import SensorEntity
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.entity_platform import AddEntitiesCallback
10 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
11 
12 from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS
13 from .entity import XS1DeviceEntity
14 
15 
17  hass: HomeAssistant,
18  config: ConfigType,
19  add_entities: AddEntitiesCallback,
20  discovery_info: DiscoveryInfoType | None = None,
21 ) -> None:
22  """Set up the XS1 sensor platform."""
23  sensors = hass.data[COMPONENT_DOMAIN][SENSORS]
24  actuators = hass.data[COMPONENT_DOMAIN][ACTUATORS]
25 
26  sensor_entities = []
27  for sensor in sensors:
28  belongs_to_climate_actuator = False
29  for actuator in actuators:
30  if (
31  actuator.type() == ActuatorType.TEMPERATURE
32  and actuator.name() in sensor.name()
33  ):
34  belongs_to_climate_actuator = True
35  break
36 
37  if not belongs_to_climate_actuator:
38  sensor_entities.append(XS1Sensor(sensor))
39 
40  add_entities(sensor_entities)
41 
42 
44  """Representation of a Sensor."""
45 
46  @property
47  def name(self):
48  """Return the name of the sensor."""
49  return self.devicedevice.name()
50 
51  @property
52  def native_value(self):
53  """Return the state of the sensor."""
54  return self.devicedevice.value()
55 
56  @property
58  """Return the unit of measurement."""
59  return self.devicedevice.unit()
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:21