1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-16 02:53:27 +01:00

Use EntityStateAttribute enum in statistics (#175957)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
epenet
2026-07-08 16:24:32 +02:00
committed by GitHub
parent 5b0ac6706d
commit 2be826bb4e
@@ -24,14 +24,13 @@ from homeassistant.components.sensor import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_UNIT_OF_MEASUREMENT,
CONF_ENTITY_ID,
CONF_NAME,
CONF_UNIQUE_ID,
PERCENTAGE,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
EntityStateAttribute,
)
from homeassistant.core import (
CALLBACK_TYPE,
@@ -841,7 +840,9 @@ class StatisticsSensor(SensorEntity):
state characteristics.
"""
base_unit: str | None = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
base_unit: str | None = new_state.attributes.get(
EntityStateAttribute.UNIT_OF_MEASUREMENT
)
unit: str | None = None
stat_type = self._state_characteristic
if self.is_binary and stat_type in STATS_BINARY_PERCENTAGE:
@@ -880,7 +881,7 @@ class StatisticsSensor(SensorEntity):
if stat_type in STATS_DATETIME:
return SensorDeviceClass.TIMESTAMP
if stat_type in STATS_NUMERIC_RETAIN_UNIT:
device_class = new_state.attributes.get(ATTR_DEVICE_CLASS)
device_class = new_state.attributes.get(EntityStateAttribute.DEVICE_CLASS)
if device_class is None:
return None
if (