mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Always update Filter sensors attr on new_state (#89096)
* always update attr * reset filter on unit change
This commit is contained in:
parent
11e268775c
commit
022fa1ee67
@ -18,10 +18,8 @@ from homeassistant.components.input_number import DOMAIN as INPUT_NUMBER_DOMAIN
|
|||||||
from homeassistant.components.recorder import get_instance, history
|
from homeassistant.components.recorder import get_instance, history
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
ATTR_STATE_CLASS,
|
ATTR_STATE_CLASS,
|
||||||
DEVICE_CLASSES as SENSOR_DEVICE_CLASSES,
|
|
||||||
DOMAIN as SENSOR_DOMAIN,
|
DOMAIN as SENSOR_DOMAIN,
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
STATE_CLASSES as SENSOR_STATE_CLASSES,
|
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
)
|
)
|
||||||
@ -273,22 +271,15 @@ class SensorFilter(SensorEntity):
|
|||||||
|
|
||||||
self._state = temp_state.state
|
self._state = temp_state.state
|
||||||
|
|
||||||
if self._attr_icon is None:
|
self._attr_icon = new_state.attributes.get(ATTR_ICON, ICON)
|
||||||
self._attr_icon = new_state.attributes.get(ATTR_ICON, ICON)
|
self._attr_device_class = new_state.attributes.get(ATTR_DEVICE_CLASS)
|
||||||
|
self._attr_state_class = new_state.attributes.get(ATTR_STATE_CLASS)
|
||||||
|
|
||||||
if (
|
if self._attr_native_unit_of_measurement != new_state.attributes.get(
|
||||||
self._attr_device_class is None
|
ATTR_UNIT_OF_MEASUREMENT
|
||||||
and new_state.attributes.get(ATTR_DEVICE_CLASS) in SENSOR_DEVICE_CLASSES
|
|
||||||
):
|
):
|
||||||
self._attr_device_class = new_state.attributes.get(ATTR_DEVICE_CLASS)
|
for filt in self._filters:
|
||||||
|
filt.reset()
|
||||||
if (
|
|
||||||
self._attr_state_class is None
|
|
||||||
and new_state.attributes.get(ATTR_STATE_CLASS) in SENSOR_STATE_CLASSES
|
|
||||||
):
|
|
||||||
self._attr_state_class = new_state.attributes.get(ATTR_STATE_CLASS)
|
|
||||||
|
|
||||||
if self._attr_native_unit_of_measurement is None:
|
|
||||||
self._attr_native_unit_of_measurement = new_state.attributes.get(
|
self._attr_native_unit_of_measurement = new_state.attributes.get(
|
||||||
ATTR_UNIT_OF_MEASUREMENT
|
ATTR_UNIT_OF_MEASUREMENT
|
||||||
)
|
)
|
||||||
@ -460,6 +451,10 @@ class Filter:
|
|||||||
"""Return whether the current filter_state should be skipped."""
|
"""Return whether the current filter_state should be skipped."""
|
||||||
return self._skip_processing
|
return self._skip_processing
|
||||||
|
|
||||||
|
def reset(self) -> None:
|
||||||
|
"""Reset filter."""
|
||||||
|
self.states.clear()
|
||||||
|
|
||||||
def _filter_state(self, new_state: FilterState) -> FilterState:
|
def _filter_state(self, new_state: FilterState) -> FilterState:
|
||||||
"""Implement filter."""
|
"""Implement filter."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user