Home Assistant Unofficial Reference 2024.12.1
number.py
Go to the documentation of this file.
1 """Support for Nexia / Trane XL Thermostats."""
2 
3 from __future__ import annotations
4 
5 from nexia.thermostat import NexiaThermostat
6 
7 from homeassistant.components.number import NumberEntity
8 from homeassistant.const import PERCENTAGE
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from .coordinator import NexiaDataUpdateCoordinator
13 from .entity import NexiaThermostatEntity
14 from .types import NexiaConfigEntry
15 from .util import percent_conv
16 
17 
19  hass: HomeAssistant,
20  config_entry: NexiaConfigEntry,
21  async_add_entities: AddEntitiesCallback,
22 ) -> None:
23  """Set up sensors for a Nexia device."""
24  coordinator = config_entry.runtime_data
25  nexia_home = coordinator.nexia_home
26 
27  entities: list[NexiaThermostatEntity] = []
28  for thermostat_id in nexia_home.get_thermostat_ids():
29  thermostat = nexia_home.get_thermostat_by_id(thermostat_id)
30  if thermostat.has_variable_fan_speed():
31  entities.append(
33  coordinator, thermostat, thermostat.get_variable_fan_speed_limits()
34  )
35  )
36  async_add_entities(entities)
37 
38 
40  """Provides Nexia Fan Speed support."""
41 
42  _attr_native_unit_of_measurement = PERCENTAGE
43  _attr_translation_key = "fan_speed"
44 
45  def __init__(
46  self,
47  coordinator: NexiaDataUpdateCoordinator,
48  thermostat: NexiaThermostat,
49  valid_range: tuple[float, float],
50  ) -> None:
51  """Initialize the entity."""
52  super().__init__(
53  coordinator,
54  thermostat,
55  unique_id=f"{thermostat.thermostat_id}_fan_speed_setpoint",
56  )
57  min_value, max_value = valid_range
58  self._attr_native_min_value_attr_native_min_value = percent_conv(min_value)
59  self._attr_native_max_value_attr_native_max_value = percent_conv(max_value)
60 
61  @property
62  def native_value(self) -> float:
63  """Return the current value."""
64  fan_speed = self._thermostat_thermostat.get_fan_speed_setpoint()
65  return percent_conv(fan_speed)
66 
67  async def async_set_native_value(self, value: float) -> None:
68  """Set a new value."""
69  await self._thermostat_thermostat.set_fan_setpoint(value / 100)
70  self._signal_thermostat_update_signal_thermostat_update()
None __init__(self, NexiaDataUpdateCoordinator coordinator, NexiaThermostat thermostat, tuple[float, float] valid_range)
Definition: number.py:50
None async_setup_entry(HomeAssistant hass, NexiaConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: number.py:22