From 012ef6bb7b01500f197fd23ac9ebd69fce8c2c47 Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Fri, 15 Apr 2022 14:38:08 +0100 Subject: [PATCH] sanitize state_classes (#70090) --- homeassistant/components/filter/sensor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/filter/sensor.py b/homeassistant/components/filter/sensor.py index 59ba706577c..46a3c0ec963 100644 --- a/homeassistant/components/filter/sensor.py +++ b/homeassistant/components/filter/sensor.py @@ -19,6 +19,7 @@ from homeassistant.components.sensor import ( DEVICE_CLASSES as SENSOR_DEVICE_CLASSES, DOMAIN as SENSOR_DOMAIN, PLATFORM_SCHEMA, + STATE_CLASSES as SENSOR_STATE_CLASSES, SensorDeviceClass, SensorEntity, ) @@ -262,7 +263,10 @@ class SensorFilter(SensorEntity): ): self._device_class = new_state.attributes.get(ATTR_DEVICE_CLASS) - if self._attr_state_class is None: + 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._unit_of_measurement is None: