Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for Nexia / Trane XL Thermostats."""
2 
3 from homeassistant.components.binary_sensor import BinarySensorEntity
4 from homeassistant.core import HomeAssistant
5 from homeassistant.helpers.entity_platform import AddEntitiesCallback
6 
7 from .entity import NexiaThermostatEntity
8 from .types import NexiaConfigEntry
9 
10 
12  hass: HomeAssistant,
13  config_entry: NexiaConfigEntry,
14  async_add_entities: AddEntitiesCallback,
15 ) -> None:
16  """Set up sensors for a Nexia device."""
17  coordinator = config_entry.runtime_data
18  nexia_home = coordinator.nexia_home
19 
20  entities = []
21  for thermostat_id in nexia_home.get_thermostat_ids():
22  thermostat = nexia_home.get_thermostat_by_id(thermostat_id)
23  entities.append(
25  coordinator, thermostat, "is_blower_active", "blower_active"
26  )
27  )
28  if thermostat.has_emergency_heat():
29  entities.append(
31  coordinator,
32  thermostat,
33  "is_emergency_heat_active",
34  "emergency_heat_active",
35  )
36  )
37 
38  async_add_entities(entities)
39 
40 
42  """Provides Nexia BinarySensor support."""
43 
44  def __init__(self, coordinator, thermostat, sensor_call, translation_key):
45  """Initialize the nexia sensor."""
46  super().__init__(
47  coordinator,
48  thermostat,
49  unique_id=f"{thermostat.thermostat_id}_{sensor_call}",
50  )
51  self._call_call = sensor_call
52  self._state_state = None
53  self._attr_translation_key_attr_translation_key = translation_key
54 
55  @property
56  def is_on(self):
57  """Return the status of the sensor."""
58  return getattr(self._thermostat_thermostat, self._call_call)()
def __init__(self, coordinator, thermostat, sensor_call, translation_key)
None async_setup_entry(HomeAssistant hass, NexiaConfigEntry config_entry, AddEntitiesCallback async_add_entities)