1 """Support for HomeMatic sensors."""
3 from __future__
import annotations
11 SensorEntityDescription,
16 CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
17 CONCENTRATION_PARTS_PER_MILLION,
21 UnitOfElectricCurrent,
22 UnitOfElectricPotential,
26 UnitOfPrecipitationDepth,
36 from .const
import ATTR_DISCOVER_DEVICES, ATTR_PARAM
37 from .entity
import HMDevice
39 _LOGGER = logging.getLogger(__name__)
42 "IPGarage": {0:
"closed", 1:
"open", 2:
"ventilation", 3:
None},
43 "RotaryHandleSensor": {0:
"closed", 1:
"tilted", 2:
"open"},
44 "RotaryHandleSensorIP": {0:
"closed", 1:
"tilted", 2:
"open"},
45 "WaterSensor": {0:
"dry", 1:
"wet", 2:
"water"},
46 "CO2Sensor": {0:
"normal", 1:
"added", 2:
"strong"},
47 "IPSmoke": {0:
"off", 1:
"primary", 2:
"intrusion", 3:
"secondary"},
54 "IPLockDLD": {0:
None, 1:
"locked", 2:
"unlocked"},
58 SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
61 native_unit_of_measurement=PERCENTAGE,
62 device_class=SensorDeviceClass.HUMIDITY,
63 state_class=SensorStateClass.MEASUREMENT,
66 key=
"ACTUAL_TEMPERATURE",
67 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
68 device_class=SensorDeviceClass.TEMPERATURE,
69 state_class=SensorStateClass.MEASUREMENT,
73 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
74 device_class=SensorDeviceClass.TEMPERATURE,
75 state_class=SensorStateClass.MEASUREMENT,
79 native_unit_of_measurement=LIGHT_LUX,
80 device_class=SensorDeviceClass.ILLUMINANCE,
81 state_class=SensorStateClass.MEASUREMENT,
84 key=
"CURRENT_ILLUMINATION",
85 native_unit_of_measurement=LIGHT_LUX,
86 device_class=SensorDeviceClass.ILLUMINANCE,
87 state_class=SensorStateClass.MEASUREMENT,
91 native_unit_of_measurement=LIGHT_LUX,
92 device_class=SensorDeviceClass.ILLUMINANCE,
93 state_class=SensorStateClass.MEASUREMENT,
96 key=
"AVERAGE_ILLUMINATION",
97 native_unit_of_measurement=LIGHT_LUX,
98 device_class=SensorDeviceClass.ILLUMINANCE,
99 state_class=SensorStateClass.MEASUREMENT,
102 key=
"LOWEST_ILLUMINATION",
103 native_unit_of_measurement=LIGHT_LUX,
104 device_class=SensorDeviceClass.ILLUMINANCE,
105 state_class=SensorStateClass.MEASUREMENT,
108 key=
"HIGHEST_ILLUMINATION",
109 native_unit_of_measurement=LIGHT_LUX,
110 device_class=SensorDeviceClass.ILLUMINANCE,
111 state_class=SensorStateClass.MEASUREMENT,
115 native_unit_of_measurement=UnitOfPower.WATT,
116 device_class=SensorDeviceClass.POWER,
117 state_class=SensorStateClass.MEASUREMENT,
121 native_unit_of_measurement=UnitOfPower.WATT,
122 device_class=SensorDeviceClass.POWER,
123 state_class=SensorStateClass.MEASUREMENT,
127 native_unit_of_measurement=UnitOfElectricCurrent.MILLIAMPERE,
128 device_class=SensorDeviceClass.CURRENT,
129 state_class=SensorStateClass.MEASUREMENT,
133 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
134 device_class=SensorDeviceClass.CO2,
135 state_class=SensorStateClass.MEASUREMENT,
138 key=
"ENERGY_COUNTER",
139 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
140 device_class=SensorDeviceClass.ENERGY,
141 state_class=SensorStateClass.TOTAL_INCREASING,
144 key=
"IEC_ENERGY_COUNTER",
145 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
146 device_class=SensorDeviceClass.ENERGY,
147 state_class=SensorStateClass.TOTAL_INCREASING,
151 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
152 device_class=SensorDeviceClass.VOLTAGE,
153 state_class=SensorStateClass.MEASUREMENT,
157 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
158 device_class=SensorDeviceClass.GAS,
161 key=
"GAS_ENERGY_COUNTER",
162 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
163 device_class=SensorDeviceClass.GAS,
164 state_class=SensorStateClass.TOTAL_INCREASING,
168 native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
169 device_class=SensorDeviceClass.PRECIPITATION,
173 native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
174 device_class=SensorDeviceClass.WIND_SPEED,
175 icon=
"mdi:weather-windy",
178 key=
"WIND_DIRECTION",
179 native_unit_of_measurement=DEGREE,
182 key=
"WIND_DIRECTION_RANGE",
183 native_unit_of_measurement=DEGREE,
186 key=
"SUNSHINEDURATION",
187 native_unit_of_measurement=
"#",
191 native_unit_of_measurement=UnitOfPressure.HPA,
192 device_class=SensorDeviceClass.PRESSURE,
193 state_class=SensorStateClass.MEASUREMENT,
197 native_unit_of_measurement=UnitOfFrequency.HERTZ,
198 device_class=SensorDeviceClass.FREQUENCY,
202 native_unit_of_measurement=
"#",
206 native_unit_of_measurement=PERCENTAGE,
209 key=
"CARRIER_SENSE_LEVEL",
210 native_unit_of_measurement=PERCENTAGE,
213 key=
"DUTY_CYCLE_LEVEL",
214 native_unit_of_measurement=PERCENTAGE,
218 native_unit_of_measurement=
"#",
219 icon=
"mdi:invert-colors",
222 key=
"MASS_CONCENTRATION_PM_1",
223 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
224 device_class=SensorDeviceClass.PM1,
225 state_class=SensorStateClass.MEASUREMENT,
228 key=
"MASS_CONCENTRATION_PM_2_5",
229 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
230 device_class=SensorDeviceClass.PM25,
231 state_class=SensorStateClass.MEASUREMENT,
234 key=
"MASS_CONCENTRATION_PM_10",
235 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
236 device_class=SensorDeviceClass.PM10,
237 state_class=SensorStateClass.MEASUREMENT,
240 key=
"MASS_CONCENTRATION_PM_1_24H_AVERAGE",
241 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
242 device_class=SensorDeviceClass.PM1,
243 state_class=SensorStateClass.MEASUREMENT,
246 key=
"MASS_CONCENTRATION_PM_2_5_24H_AVERAGE",
247 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
248 device_class=SensorDeviceClass.PM25,
249 state_class=SensorStateClass.MEASUREMENT,
252 key=
"MASS_CONCENTRATION_PM_10_24H_AVERAGE",
253 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
254 device_class=SensorDeviceClass.PM10,
255 state_class=SensorStateClass.MEASUREMENT,
261 key=
"SMOKE_DETECTOR_ALARM_STATUS",
267 key=
"WIND_DIR_RANGE",
270 key=
"CONCENTRATION_STATUS",
273 key=
"PASSAGE_COUNTER_VALUE",
291 entity_registry_enabled_default=
True,
298 add_entities: AddEntitiesCallback,
299 discovery_info: DiscoveryInfoType |
None =
None,
301 """Set up the HomeMatic sensor platform."""
302 if discovery_info
is None:
306 for conf
in discovery_info[ATTR_DISCOVER_DEVICES]:
307 state = conf.get(ATTR_PARAM)
308 if (entity_desc := SENSOR_DESCRIPTIONS.get(state))
is None:
309 name = conf.get(ATTR_NAME)
312 "Sensor (%s) entity description is missing. Sensor state (%s) needs"
318 entity_desc = copy(DEFAULT_SENSOR_DESCRIPTION)
320 new_device =
HMSensor(conf, entity_desc)
321 devices.append(new_device)
327 """Representation of a HomeMatic sensor."""
331 """Return the state of the sensor."""
333 name = self.
_hmdevice_hmdevice.__class__.__name__
334 if name
in HM_STATE_HA_CAST:
341 """Generate a data dictionary (self._data) from metadata."""
345 _LOGGER.critical(
"Unable to initialize sensor: %s", self.
_name_name)
def _init_data_struct(self)
web.Response get(self, web.Request request, str config_key)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
def add_entities(account, async_add_entities, tracked)