mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Add state_class measurements in wiffi integration (#54279)
* add support for state_class measurements in wiffi integration * use new STATE_CLASS_TOTAL_INCREASING for metered entities like - amount of rainfall per hour/day - rainfall hours per day - sunshine hours per day * Update homeassistant/components/wiffi/sensor.py Co-authored-by: Greg <greg.diehl.gtd@gmail.com> Co-authored-by: Greg <greg.diehl.gtd@gmail.com>
This commit is contained in:
parent
4d7e3cde5a
commit
e5642a8648
@ -222,3 +222,11 @@ class WiffiEntity(Entity):
|
||||
):
|
||||
self._value = None
|
||||
self.async_write_ha_state()
|
||||
|
||||
def _is_measurement_entity(self):
|
||||
"""Measurement entities have a value in present time."""
|
||||
return not self._name.endswith("_gestern") and not self._is_metered_entity()
|
||||
|
||||
def _is_metered_entity(self):
|
||||
"""Metered entities have a value that keeps increasing until reset."""
|
||||
return self._name.endswith("_pro_h") or self._name.endswith("_heute")
|
||||
|
@ -5,6 +5,8 @@ from homeassistant.components.sensor import (
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
SensorEntity,
|
||||
)
|
||||
from homeassistant.const import DEGREE, PRESSURE_MBAR, TEMP_CELSIUS
|
||||
@ -70,6 +72,12 @@ class NumberEntity(WiffiEntity, SensorEntity):
|
||||
metric.unit_of_measurement, metric.unit_of_measurement
|
||||
)
|
||||
self._value = metric.value
|
||||
|
||||
if self._is_measurement_entity():
|
||||
self._attr_state_class = STATE_CLASS_MEASUREMENT
|
||||
elif self._is_metered_entity():
|
||||
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||
|
||||
self.reset_expiration_date()
|
||||
|
||||
@property
|
||||
@ -97,7 +105,9 @@ class NumberEntity(WiffiEntity, SensorEntity):
|
||||
self._unit_of_measurement = UOM_MAP.get(
|
||||
metric.unit_of_measurement, metric.unit_of_measurement
|
||||
)
|
||||
|
||||
self._value = metric.value
|
||||
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user