From 2be826bb4edbc97d98ff9dfc49c3fdbde9cbe90b Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 8 Jul 2026 16:24:32 +0200 Subject: [PATCH] Use EntityStateAttribute enum in statistics (#175957) Co-authored-by: Claude Opus 4.8 (1M context) --- homeassistant/components/statistics/sensor.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/statistics/sensor.py b/homeassistant/components/statistics/sensor.py index 688d999a3c64..23c595e16d7e 100644 --- a/homeassistant/components/statistics/sensor.py +++ b/homeassistant/components/statistics/sensor.py @@ -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 (