Fix sensor statistics collection with empty states (#52393)
This commit is contained in:
parent
2097ab76f5
commit
57fbb1c3d9
1 changed files with 3 additions and 1 deletions
|
@ -153,12 +153,14 @@ def _normalize_states(
|
||||||
entity_history: list[State], device_class: str, entity_id: str
|
entity_history: list[State], device_class: str, entity_id: str
|
||||||
) -> tuple[str | None, list[tuple[float, State]]]:
|
) -> tuple[str | None, list[tuple[float, State]]]:
|
||||||
"""Normalize units."""
|
"""Normalize units."""
|
||||||
|
unit = None
|
||||||
|
|
||||||
if device_class not in UNIT_CONVERSIONS:
|
if device_class not in UNIT_CONVERSIONS:
|
||||||
# We're not normalizing this device class, return the state as they are
|
# We're not normalizing this device class, return the state as they are
|
||||||
fstates = [
|
fstates = [
|
||||||
(float(el.state), el) for el in entity_history if _is_number(el.state)
|
(float(el.state), el) for el in entity_history if _is_number(el.state)
|
||||||
]
|
]
|
||||||
|
if fstates:
|
||||||
unit = fstates[0][1].attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
unit = fstates[0][1].attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||||
return unit, fstates
|
return unit, fstates
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue