Skip to content
Snippets Groups Projects
Unverified Commit 8d37fd08 authored by Thomas Lovén's avatar Thomas Lovén Committed by GitHub
Browse files

Fix integration sensors sometimes not getting device_class or unit_of_measurement (#54802)

parent bce7c739
No related branches found
No related tags found
No related merge requests found
......@@ -145,12 +145,6 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
"""Handle the sensor state changes."""
old_state = event.data.get("old_state")
new_state = event.data.get("new_state")
if (
old_state is None
or old_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE)
or new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE)
):
return
if self._unit_of_measurement is None:
unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
......@@ -162,6 +156,14 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
and new_state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_POWER
):
self._attr_device_class = DEVICE_CLASS_ENERGY
if (
old_state is None
or old_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE)
or new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE)
):
return
try:
# integration as the Riemann integral of previous measures.
area = 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment