1 """Support for Nexia / Trane XL Thermostats."""
3 from __future__
import annotations
5 from nexia.const
import UNIT_CELSIUS
6 from nexia.thermostat
import NexiaThermostat
17 from .entity
import NexiaThermostatEntity, NexiaThermostatZoneEntity
18 from .types
import NexiaConfigEntry
19 from .util
import percent_conv
24 config_entry: NexiaConfigEntry,
25 async_add_entities: AddEntitiesCallback,
27 """Set up sensors for a Nexia device."""
29 coordinator = config_entry.runtime_data
30 nexia_home = coordinator.nexia_home
31 entities: list[NexiaThermostatEntity] = []
34 for thermostat_id
in nexia_home.get_thermostat_ids():
35 thermostat: NexiaThermostat = nexia_home.get_thermostat_by_id(thermostat_id)
53 "get_air_cleaner_mode",
61 if thermostat.has_variable_speed_compressor():
66 "get_current_compressor_speed",
67 "current_compressor_speed",
70 SensorStateClass.MEASUREMENT,
78 "get_requested_compressor_speed",
79 "requested_compressor_speed",
82 SensorStateClass.MEASUREMENT,
87 if thermostat.has_outdoor_temperature():
88 if thermostat.get_unit() == UNIT_CELSIUS:
89 unit = UnitOfTemperature.CELSIUS
91 unit = UnitOfTemperature.FAHRENHEIT
96 "get_outdoor_temperature",
97 "outdoor_temperature",
98 SensorDeviceClass.TEMPERATURE,
100 SensorStateClass.MEASUREMENT,
104 if thermostat.has_relative_humidity():
109 "get_relative_humidity",
111 SensorDeviceClass.HUMIDITY,
113 SensorStateClass.MEASUREMENT,
119 for zone_id
in thermostat.get_zone_ids():
120 zone = thermostat.get_zone_by_id(zone_id)
121 if thermostat.get_unit() == UNIT_CELSIUS:
122 unit = UnitOfTemperature.CELSIUS
124 unit = UnitOfTemperature.FAHRENHEIT
132 SensorDeviceClass.TEMPERATURE,
134 SensorStateClass.MEASUREMENT,
141 coordinator, zone,
"get_status",
"zone_status",
None,
None,
None
149 "get_setpoint_status",
150 "zone_setpoint_status",
161 """Provides Nexia thermostat sensor support."""
174 """Initialize the sensor."""
178 unique_id=f
"{thermostat.thermostat_id}_{sensor_call}",
185 if translation_key
is not None:
190 """Return the state of the sensor."""
194 if isinstance(val, float):
200 """Nexia Zone Sensor Support."""
213 """Create a zone sensor."""
218 unique_id=f
"{zone.zone_id}_{sensor_call}",
225 if translation_key
is not None:
230 """Return the state of the sensor."""
231 val = getattr(self.
_zone_zone, self.
_call_call)()
234 if isinstance(val, float):
_attr_native_unit_of_measurement
def __init__(self, coordinator, thermostat, sensor_call, translation_key, sensor_class, sensor_unit, state_class, modifier=None)
def __init__(self, coordinator, zone, sensor_call, translation_key, sensor_class, sensor_unit, state_class, modifier=None)
_attr_native_unit_of_measurement
None async_setup_entry(HomeAssistant hass, NexiaConfigEntry config_entry, AddEntitiesCallback async_add_entities)