1 """Support for Ecobee sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from pyecobee.const
import ECOBEE_STATE_CALIBRATING, ECOBEE_STATE_UNKNOWN
12 SensorEntityDescription,
17 CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
18 CONCENTRATION_PARTS_PER_MILLION,
26 from .const
import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER
29 @dataclass(frozen=True, kw_only=True)
31 """Represent the ecobee sensor entity description."""
33 runtime_key: str |
None
36 SENSOR_TYPES: tuple[EcobeeSensorEntityDescription, ...] = (
39 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
40 device_class=SensorDeviceClass.TEMPERATURE,
41 state_class=SensorStateClass.MEASUREMENT,
46 native_unit_of_measurement=PERCENTAGE,
47 device_class=SensorDeviceClass.HUMIDITY,
48 state_class=SensorStateClass.MEASUREMENT,
53 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
54 device_class=SensorDeviceClass.CO2,
55 state_class=SensorStateClass.MEASUREMENT,
56 runtime_key=
"actualCO2",
60 device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS,
61 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
62 state_class=SensorStateClass.MEASUREMENT,
63 runtime_key=
"actualVOC",
67 device_class=SensorDeviceClass.AQI,
68 state_class=SensorStateClass.MEASUREMENT,
69 runtime_key=
"actualAQScore",
76 config_entry: ConfigEntry,
77 async_add_entities: AddEntitiesCallback,
79 """Set up ecobee sensors."""
80 data = hass.data[DOMAIN]
83 for index
in range(len(data.ecobee.thermostats))
84 for sensor
in data.ecobee.get_remote_sensors(index)
85 for item
in sensor[
"capability"]
86 for description
in SENSOR_TYPES
87 if description.key == item[
"type"]
94 """Representation of an Ecobee sensor."""
96 _attr_has_entity_name =
True
98 entity_description: EcobeeSensorEntityDescription
105 description: EcobeeSensorEntityDescription,
107 """Initialize the sensor."""
116 """Return a unique identifier for this sensor."""
117 for sensor
in self.
datadata.ecobee.get_remote_sensors(self.
indexindex):
120 return f
"{sensor['code']}-{self.device_class}"
121 thermostat = self.
datadata.ecobee.get_thermostat(self.
indexindex)
122 return f
"{thermostat['identifier']}-{sensor['id']}-{self.device_class}"
127 """Return device information for this sensor."""
130 for sensor
in self.
datadata.ecobee.get_remote_sensors(self.
indexindex):
134 identifier = sensor[
"code"]
135 model =
"ecobee Room Sensor"
137 thermostat = self.
datadata.ecobee.get_thermostat(self.
indexindex)
138 identifier = thermostat[
"identifier"]
141 f
"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat"
148 if identifier
is not None and model
is not None:
150 identifiers={(DOMAIN, identifier)},
151 manufacturer=MANUFACTURER,
159 """Return true if device is available."""
160 thermostat = self.
datadata.ecobee.get_thermostat(self.
indexindex)
161 return thermostat[
"runtime"][
"connected"]
165 """Return the state of the sensor."""
167 ECOBEE_STATE_CALIBRATING,
168 ECOBEE_STATE_UNKNOWN,
179 """Get the latest state of the sensor."""
181 for sensor
in self.
datadata.ecobee.get_remote_sensors(self.
indexindex):
184 for item
in sensor[
"capability"]:
188 self.
_state_state = item[
"value"]
190 thermostat = self.
datadata.ecobee.get_thermostat(self.
indexindex)
191 self.
_state_state = thermostat[
"runtime"][
DeviceInfo|None device_info(self)
None __init__(self, data, sensor_name, sensor_index, EcobeeSensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
IssData update(pyiss.ISS iss)