-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber.py
More file actions
70 lines (57 loc) · 2.31 KB
/
number.py
File metadata and controls
70 lines (57 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Support for Nexia / Trane XL Thermostats."""
from __future__ import annotations
from .nexiaux360.thermostat import NexiaThermostat
from homeassistant.components.number import NumberEntity
from homeassistant.const import PERCENTAGE
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .coordinator import NexiaDataUpdateCoordinator
from .entity import NexiaThermostatEntity
from .types import NexiaConfigEntry
from .util import percent_conv
async def async_setup_entry(
hass: HomeAssistant,
config_entry: NexiaConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up sensors for a Nexia device."""
coordinator = config_entry.runtime_data
nexia_home = coordinator.nexia_home
entities: list[NexiaThermostatEntity] = []
for thermostat_id in nexia_home.get_thermostat_ids():
thermostat = nexia_home.get_thermostat_by_id(thermostat_id)
if thermostat.has_variable_fan_speed():
entities.append(
NexiaFanSpeedEntity(
coordinator, thermostat, thermostat.get_variable_fan_speed_limits()
)
)
async_add_entities(entities)
class NexiaFanSpeedEntity(NexiaThermostatEntity, NumberEntity):
"""Provides Nexia Fan Speed support."""
_attr_native_unit_of_measurement = PERCENTAGE
_attr_translation_key = "fan_speed"
def __init__(
self,
coordinator: NexiaDataUpdateCoordinator,
thermostat: NexiaThermostat,
valid_range: tuple[float, float],
) -> None:
"""Initialize the entity."""
super().__init__(
coordinator,
thermostat,
unique_id=f"{thermostat.thermostat_id}_fan_speed_setpoint",
)
min_value, max_value = valid_range
self._attr_native_min_value = percent_conv(min_value)
self._attr_native_max_value = percent_conv(max_value)
@property
def native_value(self) -> float:
"""Return the current value."""
fan_speed = self._thermostat.get_fan_speed_setpoint()
return percent_conv(fan_speed)
async def async_set_native_value(self, value: float) -> None:
"""Set a new value."""
await self._thermostat.set_fan_setpoint(value / 100)
self._signal_thermostat_update()