1 """Support for Toon sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
10 SensorEntityDescription,
24 from .const
import CURRENCY_EUR, DOMAIN, VOLUME_CM3, VOLUME_LMIN
25 from .coordinator
import ToonDataUpdateCoordinator
27 ToonBoilerDeviceEntity,
28 ToonDisplayDeviceEntity,
29 ToonElectricityMeterDeviceEntity,
31 ToonGasMeterDeviceEntity,
32 ToonRequiredKeysMixin,
33 ToonSolarDeviceEntity,
34 ToonWaterMeterDeviceEntity,
39 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
41 """Set up Toon sensors based on a config entry."""
42 coordinator = hass.data[DOMAIN][entry.entry_id]
45 description.cls(coordinator, description)
for description
in SENSOR_ENTITIES
48 if coordinator.data.agreement.is_toon_solar:
51 description.cls(coordinator, description)
52 for description
in SENSOR_ENTITIES_SOLAR
56 if coordinator.data.thermostat.have_opentherm_boiler:
59 description.cls(coordinator, description)
60 for description
in SENSOR_ENTITIES_BOILER
68 """Defines a Toon sensor."""
70 entity_description: ToonSensorEntityDescription
74 coordinator: ToonDataUpdateCoordinator,
75 description: ToonSensorEntityDescription,
77 """Initialize the Toon sensor."""
84 f
"{DOMAIN}_{coordinator.data.agreement.agreement_id}_sensor_{description.key}"
89 """Return the state of the sensor."""
90 section = getattr(self.coordinator.data, self.
entity_descriptionentity_description.section)
95 """Defines a Electricity Meter sensor."""
98 class ToonGasMeterDeviceSensor(ToonSensor, ToonGasMeterDeviceEntity):
99 """Defines a Gas Meter sensor."""
103 """Defines a Water Meter sensor."""
107 """Defines a Solar sensor."""
111 """Defines a Boiler sensor."""
115 """Defines a Display sensor."""
118 @dataclass(frozen=
True)
120 """Mixin for sensor required keys."""
122 cls: type[ToonSensor]
125 @dataclass(frozen=True)
127 """Describes Toon sensor entity."""
130 SENSOR_ENTITIES: tuple[ToonSensorEntityDescription, ...] = (
131 ToonSensorEntityDescription(
132 key=
"current_display_temperature",
134 section=
"thermostat",
135 measurement=
"current_display_temperature",
136 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
137 device_class=SensorDeviceClass.TEMPERATURE,
138 entity_registry_enabled_default=
False,
139 state_class=SensorStateClass.MEASUREMENT,
140 cls=ToonDisplayDeviceSensor,
142 ToonSensorEntityDescription(
143 key=
"current_humidity",
145 section=
"thermostat",
146 measurement=
"current_humidity",
147 native_unit_of_measurement=PERCENTAGE,
148 device_class=SensorDeviceClass.HUMIDITY,
149 entity_registry_enabled_default=
False,
150 state_class=SensorStateClass.MEASUREMENT,
151 cls=ToonDisplayDeviceSensor,
153 ToonSensorEntityDescription(
155 name=
"Average Gas Usage",
157 measurement=
"average",
158 native_unit_of_measurement=VOLUME_CM3,
159 icon=
"mdi:gas-cylinder",
160 cls=ToonGasMeterDeviceSensor,
162 ToonSensorEntityDescription(
163 key=
"gas_average_daily",
164 name=
"Average Daily Gas Usage",
166 measurement=
"day_average",
167 device_class=SensorDeviceClass.GAS,
168 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
169 entity_registry_enabled_default=
False,
170 cls=ToonGasMeterDeviceSensor,
172 ToonSensorEntityDescription(
173 key=
"gas_daily_usage",
174 name=
"Gas Usage Today",
176 measurement=
"day_usage",
177 device_class=SensorDeviceClass.GAS,
178 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
179 cls=ToonGasMeterDeviceSensor,
181 ToonSensorEntityDescription(
182 key=
"gas_daily_cost",
183 name=
"Gas Cost Today",
185 measurement=
"day_cost",
186 device_class=SensorDeviceClass.MONETARY,
187 state_class=SensorStateClass.TOTAL,
188 native_unit_of_measurement=CURRENCY_EUR,
189 icon=
"mdi:gas-cylinder",
190 cls=ToonGasMeterDeviceSensor,
192 ToonSensorEntityDescription(
193 key=
"gas_meter_reading",
197 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
198 state_class=SensorStateClass.TOTAL_INCREASING,
199 device_class=SensorDeviceClass.GAS,
200 cls=ToonGasMeterDeviceSensor,
202 ToonSensorEntityDescription(
204 name=
"Current Gas Usage",
206 measurement=
"current",
207 native_unit_of_measurement=VOLUME_CM3,
208 icon=
"mdi:gas-cylinder",
209 cls=ToonGasMeterDeviceSensor,
211 ToonSensorEntityDescription(
213 name=
"Average Power Usage",
214 section=
"power_usage",
215 measurement=
"average",
216 native_unit_of_measurement=UnitOfPower.WATT,
217 device_class=SensorDeviceClass.POWER,
218 entity_registry_enabled_default=
False,
219 cls=ToonElectricityMeterDeviceSensor,
221 ToonSensorEntityDescription(
222 key=
"power_average_daily",
223 name=
"Average Daily Energy Usage",
224 section=
"power_usage",
225 measurement=
"day_average",
226 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
227 device_class=SensorDeviceClass.ENERGY,
228 entity_registry_enabled_default=
False,
229 cls=ToonElectricityMeterDeviceSensor,
231 ToonSensorEntityDescription(
232 key=
"power_daily_cost",
233 name=
"Energy Cost Today",
234 section=
"power_usage",
235 measurement=
"day_cost",
236 device_class=SensorDeviceClass.MONETARY,
237 state_class=SensorStateClass.TOTAL,
238 native_unit_of_measurement=CURRENCY_EUR,
239 icon=
"mdi:power-plug",
240 cls=ToonElectricityMeterDeviceSensor,
242 ToonSensorEntityDescription(
243 key=
"power_daily_value",
244 name=
"Energy Usage Today",
245 section=
"power_usage",
246 measurement=
"day_usage",
247 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
248 device_class=SensorDeviceClass.ENERGY,
249 cls=ToonElectricityMeterDeviceSensor,
251 ToonSensorEntityDescription(
252 key=
"power_meter_reading",
253 name=
"Electricity Meter Feed IN Tariff 1",
254 section=
"power_usage",
255 measurement=
"meter_high",
256 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
257 device_class=SensorDeviceClass.ENERGY,
258 state_class=SensorStateClass.TOTAL_INCREASING,
259 cls=ToonElectricityMeterDeviceSensor,
261 ToonSensorEntityDescription(
262 key=
"power_meter_reading_low",
263 name=
"Electricity Meter Feed IN Tariff 2",
264 section=
"power_usage",
265 measurement=
"meter_low",
266 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
267 device_class=SensorDeviceClass.ENERGY,
268 state_class=SensorStateClass.TOTAL_INCREASING,
269 cls=ToonElectricityMeterDeviceSensor,
271 ToonSensorEntityDescription(
273 name=
"Current Power Usage",
274 section=
"power_usage",
275 measurement=
"current",
276 native_unit_of_measurement=UnitOfPower.WATT,
277 device_class=SensorDeviceClass.POWER,
278 state_class=SensorStateClass.MEASUREMENT,
279 cls=ToonElectricityMeterDeviceSensor,
281 ToonSensorEntityDescription(
282 key=
"solar_meter_reading_produced",
283 name=
"Electricity Meter Feed OUT Tariff 1",
284 section=
"power_usage",
285 measurement=
"meter_produced_high",
286 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
287 device_class=SensorDeviceClass.ENERGY,
288 state_class=SensorStateClass.TOTAL_INCREASING,
289 cls=ToonElectricityMeterDeviceSensor,
291 ToonSensorEntityDescription(
292 key=
"solar_meter_reading_low_produced",
293 name=
"Electricity Meter Feed OUT Tariff 2",
294 section=
"power_usage",
295 measurement=
"meter_produced_low",
296 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
297 device_class=SensorDeviceClass.ENERGY,
298 state_class=SensorStateClass.TOTAL_INCREASING,
299 cls=ToonElectricityMeterDeviceSensor,
301 ToonSensorEntityDescription(
303 name=
"Average Water Usage",
304 section=
"water_usage",
305 measurement=
"average",
306 native_unit_of_measurement=VOLUME_LMIN,
308 entity_registry_enabled_default=
False,
309 cls=ToonWaterMeterDeviceSensor,
311 ToonSensorEntityDescription(
312 key=
"water_average_daily",
313 name=
"Average Daily Water Usage",
314 section=
"water_usage",
315 measurement=
"day_average",
316 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
318 entity_registry_enabled_default=
False,
319 cls=ToonWaterMeterDeviceSensor,
320 device_class=SensorDeviceClass.WATER,
322 ToonSensorEntityDescription(
323 key=
"water_daily_usage",
324 name=
"Water Usage Today",
325 section=
"water_usage",
326 measurement=
"day_usage",
327 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
329 entity_registry_enabled_default=
False,
330 cls=ToonWaterMeterDeviceSensor,
331 device_class=SensorDeviceClass.WATER,
333 ToonSensorEntityDescription(
334 key=
"water_meter_reading",
336 section=
"water_usage",
338 native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
340 entity_registry_enabled_default=
False,
341 state_class=SensorStateClass.TOTAL_INCREASING,
342 cls=ToonWaterMeterDeviceSensor,
343 device_class=SensorDeviceClass.WATER,
345 ToonSensorEntityDescription(
347 name=
"Current Water Usage",
348 section=
"water_usage",
349 measurement=
"current",
350 native_unit_of_measurement=VOLUME_LMIN,
351 icon=
"mdi:water-pump",
352 entity_registry_enabled_default=
False,
353 state_class=SensorStateClass.MEASUREMENT,
354 cls=ToonWaterMeterDeviceSensor,
356 ToonSensorEntityDescription(
357 key=
"water_daily_cost",
358 name=
"Water Cost Today",
359 section=
"water_usage",
360 measurement=
"day_cost",
361 device_class=SensorDeviceClass.MONETARY,
362 state_class=SensorStateClass.TOTAL,
363 native_unit_of_measurement=CURRENCY_EUR,
364 icon=
"mdi:water-pump",
365 entity_registry_enabled_default=
False,
366 cls=ToonWaterMeterDeviceSensor,
370 SENSOR_ENTITIES_SOLAR: tuple[ToonSensorEntityDescription, ...] = (
371 ToonSensorEntityDescription(
373 name=
"Current Solar Power Production",
374 section=
"power_usage",
375 measurement=
"current_solar",
376 native_unit_of_measurement=UnitOfPower.WATT,
377 device_class=SensorDeviceClass.POWER,
378 state_class=SensorStateClass.MEASUREMENT,
379 cls=ToonSolarDeviceSensor,
381 ToonSensorEntityDescription(
383 name=
"Max Solar Power Production Today",
384 section=
"power_usage",
385 measurement=
"day_max_solar",
386 native_unit_of_measurement=UnitOfPower.WATT,
387 device_class=SensorDeviceClass.POWER,
388 cls=ToonSolarDeviceSensor,
390 ToonSensorEntityDescription(
391 key=
"solar_produced",
392 name=
"Solar Power Production to Grid",
393 section=
"power_usage",
394 measurement=
"current_produced",
395 native_unit_of_measurement=UnitOfPower.WATT,
396 device_class=SensorDeviceClass.POWER,
397 state_class=SensorStateClass.MEASUREMENT,
398 cls=ToonSolarDeviceSensor,
400 ToonSensorEntityDescription(
401 key=
"power_usage_day_produced_solar",
402 name=
"Solar Energy Produced Today",
403 section=
"power_usage",
404 measurement=
"day_produced_solar",
405 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
406 device_class=SensorDeviceClass.ENERGY,
407 state_class=SensorStateClass.TOTAL_INCREASING,
408 cls=ToonSolarDeviceSensor,
410 ToonSensorEntityDescription(
411 key=
"power_usage_day_to_grid_usage",
412 name=
"Energy Produced To Grid Today",
413 section=
"power_usage",
414 measurement=
"day_to_grid_usage",
415 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
416 device_class=SensorDeviceClass.ENERGY,
417 entity_registry_enabled_default=
False,
418 cls=ToonSolarDeviceSensor,
420 ToonSensorEntityDescription(
421 key=
"power_usage_day_from_grid_usage",
422 name=
"Energy Usage From Grid Today",
423 section=
"power_usage",
424 measurement=
"day_from_grid_usage",
425 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
426 device_class=SensorDeviceClass.ENERGY,
427 entity_registry_enabled_default=
False,
428 cls=ToonSolarDeviceSensor,
430 ToonSensorEntityDescription(
431 key=
"solar_average_produced",
432 name=
"Average Solar Power Production to Grid",
433 section=
"power_usage",
434 measurement=
"average_produced",
435 native_unit_of_measurement=UnitOfPower.WATT,
436 device_class=SensorDeviceClass.POWER,
437 entity_registry_enabled_default=
False,
438 cls=ToonSolarDeviceSensor,
440 ToonSensorEntityDescription(
441 key=
"power_usage_current_covered_by_solar",
442 name=
"Current Power Usage Covered By Solar",
443 section=
"power_usage",
444 measurement=
"current_covered_by_solar",
445 native_unit_of_measurement=PERCENTAGE,
446 icon=
"mdi:solar-power",
447 state_class=SensorStateClass.MEASUREMENT,
448 cls=ToonSolarDeviceSensor,
452 SENSOR_ENTITIES_BOILER: tuple[ToonSensorEntityDescription, ...] = (
453 ToonSensorEntityDescription(
454 key=
"thermostat_info_current_modulation_level",
455 name=
"Boiler Modulation Level",
456 section=
"thermostat",
457 measurement=
"current_modulation_level",
458 native_unit_of_measurement=PERCENTAGE,
460 entity_registry_enabled_default=
False,
461 state_class=SensorStateClass.MEASUREMENT,
462 cls=ToonBoilerDeviceSensor,
str|None native_value(self)
None __init__(self, ToonDataUpdateCoordinator coordinator, ToonSensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)