Home Assistant Unofficial Reference 2024.12.1
number.py
Go to the documentation of this file.
1 """Support for using number with ecobee thermostats."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Awaitable, Callable
6 from dataclasses import dataclass
7 import logging
8 
10  NumberDeviceClass,
11  NumberEntity,
12  NumberEntityDescription,
13  NumberMode,
14 )
15 from homeassistant.config_entries import ConfigEntry
16 from homeassistant.const import UnitOfTemperature, UnitOfTime
17 from homeassistant.core import HomeAssistant
18 from homeassistant.helpers.entity_platform import AddEntitiesCallback
19 
20 from . import EcobeeData
21 from .const import DOMAIN
22 from .entity import EcobeeBaseEntity
23 
24 _LOGGER = logging.getLogger(__name__)
25 
26 
27 @dataclass(frozen=True, kw_only=True)
29  """Class describing Ecobee number entities."""
30 
31  ecobee_setting_key: str
32  set_fn: Callable[[EcobeeData, int, int], Awaitable]
33 
34 
35 VENTILATOR_NUMBERS = (
37  key="home",
38  translation_key="ventilator_min_type_home",
39  ecobee_setting_key="ventilatorMinOnTimeHome",
40  set_fn=lambda data, id, min_time: data.ecobee.set_ventilator_min_on_time_home(
41  id, min_time
42  ),
43  ),
45  key="away",
46  translation_key="ventilator_min_type_away",
47  ecobee_setting_key="ventilatorMinOnTimeAway",
48  set_fn=lambda data, id, min_time: data.ecobee.set_ventilator_min_on_time_away(
49  id, min_time
50  ),
51  ),
52 )
53 
54 
56  hass: HomeAssistant,
57  config_entry: ConfigEntry,
58  async_add_entities: AddEntitiesCallback,
59 ) -> None:
60  """Set up the ecobee thermostat number entity."""
61  data: EcobeeData = hass.data[DOMAIN]
62 
63  assert data is not None
64 
65  entities: list[NumberEntity] = [
66  EcobeeVentilatorMinTime(data, index, numbers)
67  for index, thermostat in enumerate(data.ecobee.thermostats)
68  if thermostat["settings"]["ventilatorType"] != "none"
69  for numbers in VENTILATOR_NUMBERS
70  ]
71 
72  _LOGGER.debug("Adding compressor min temp number (if present)")
73  entities.extend(
74  (
75  EcobeeCompressorMinTemp(data, index)
76  for index, thermostat in enumerate(data.ecobee.thermostats)
77  if thermostat["settings"]["hasHeatPump"]
78  )
79  )
80 
81  async_add_entities(entities, True)
82 
83 
85  """A number class, representing min time for an ecobee thermostat with ventilator attached."""
86 
87  entity_description: EcobeeNumberEntityDescription
88 
89  _attr_native_min_value = 0
90  _attr_native_max_value = 60
91  _attr_native_step = 5
92  _attr_native_unit_of_measurement = UnitOfTime.MINUTES
93  _attr_has_entity_name = True
94 
95  def __init__(
96  self,
97  data: EcobeeData,
98  thermostat_index: int,
99  description: EcobeeNumberEntityDescription,
100  ) -> None:
101  """Initialize ecobee ventilator platform."""
102  super().__init__(data, thermostat_index)
103  self.entity_descriptionentity_description = description
104  self._attr_unique_id_attr_unique_id = f"{self.base_unique_id}_ventilator_{description.key}"
105  self.update_without_throttleupdate_without_throttle = False
106 
107  async def async_update(self) -> None:
108  """Get the latest state from the thermostat."""
109  if self.update_without_throttleupdate_without_throttle:
110  await self.datadata.update(no_throttle=True)
111  self.update_without_throttleupdate_without_throttle = False
112  else:
113  await self.datadata.update()
114  self._attr_native_value_attr_native_value = self.thermostatthermostat["settings"][
115  self.entity_descriptionentity_description.ecobee_setting_key
116  ]
117 
118  def set_native_value(self, value: float) -> None:
119  """Set new ventilator Min On Time value."""
120  self.entity_descriptionentity_description.set_fn(self.datadata, self.thermostat_indexthermostat_index, int(value))
121  self.update_without_throttleupdate_without_throttle = True
122 
123 
125  """Minimum outdoor temperature at which the compressor will operate.
126 
127  This applies more to air source heat pumps than geothermal. This serves as a safety
128  feature (compressors have a minimum operating temperature) as well as
129  providing the ability to choose fuel in a dual-fuel system (i.e. choose between
130  electrical heat pump and fossil auxiliary heat depending on Time of Use, Solar,
131  etc.).
132  Note that python-ecobee-api refers to this as Aux Cutover Threshold, but Ecobee
133  uses Compressor Protection Min Temp.
134  """
135 
136  _attr_device_class = NumberDeviceClass.TEMPERATURE
137  _attr_has_entity_name = True
138  _attr_icon = "mdi:thermometer-off"
139  _attr_mode = NumberMode.BOX
140  _attr_native_min_value = -25
141  _attr_native_max_value = 66
142  _attr_native_step = 5
143  _attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT
144  _attr_translation_key = "compressor_protection_min_temp"
145 
146  def __init__(
147  self,
148  data: EcobeeData,
149  thermostat_index: int,
150  ) -> None:
151  """Initialize ecobee compressor min temperature."""
152  super().__init__(data, thermostat_index)
153  self._attr_unique_id_attr_unique_id = f"{self.base_unique_id}_compressor_protection_min_temp"
154  self.update_without_throttleupdate_without_throttle = False
155 
156  async def async_update(self) -> None:
157  """Get the latest state from the thermostat."""
158  if self.update_without_throttleupdate_without_throttle:
159  await self.datadata.update(no_throttle=True)
160  self.update_without_throttleupdate_without_throttle = False
161  else:
162  await self.datadata.update()
163 
164  self._attr_native_value_attr_native_value = (
165  (self.thermostatthermostat["settings"]["compressorProtectionMinTemp"]) / 10
166  )
167 
168  def set_native_value(self, value: float) -> None:
169  """Set new compressor minimum temperature."""
170  self.datadata.ecobee.set_aux_cutover_threshold(self.thermostat_indexthermostat_index, value)
171  self.update_without_throttleupdate_without_throttle = True
None __init__(self, EcobeeData data, int thermostat_index)
Definition: number.py:150
None __init__(self, EcobeeData data, int thermostat_index, EcobeeNumberEntityDescription description)
Definition: number.py:100
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: number.py:59
IssData update(pyiss.ISS iss)
Definition: __init__.py:33