diff --git a/homeassistant/components/wiffi/__init__.py b/homeassistant/components/wiffi/__init__.py index 55b13921c1c..e155a48fd72 100644 --- a/homeassistant/components/wiffi/__init__.py +++ b/homeassistant/components/wiffi/__init__.py @@ -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") diff --git a/homeassistant/components/wiffi/sensor.py b/homeassistant/components/wiffi/sensor.py index b9bcd317b46..c16ae3c6aca 100644 --- a/homeassistant/components/wiffi/sensor.py +++ b/homeassistant/components/wiffi/sensor.py @@ -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()