Migrate timer entity attributes to StrEnum (#175754)

This commit is contained in:
epenet
2026-07-06 15:47:26 +02:00
committed by GitHub
parent 479584f459
commit 5af897a457
2 changed files with 27 additions and 7 deletions
+13 -7
View File
@@ -7,7 +7,7 @@ from typing import Any, Self, override
import voluptuous as vol
from homeassistant.const import (
from homeassistant.const import ( # noqa: F401
ATTR_EDITABLE,
ATTR_ENTITY_ID,
CONF_ICON,
@@ -26,6 +26,8 @@ from homeassistant.helpers.storage import Store
from homeassistant.helpers.typing import ConfigType, VolDictType
from homeassistant.util import dt as dt_util
from .const import TimerEntityStateAttribute
_LOGGER = logging.getLogger(__name__)
DOMAIN = "timer"
@@ -256,16 +258,20 @@ class Timer(collection.CollectionEntity, RestoreEntity):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
attrs: dict[str, Any] = {
ATTR_DURATION: _format_timedelta(self._running_duration),
ATTR_EDITABLE: self.editable,
ATTR_LAST_TRANSITION: self._last_transition,
TimerEntityStateAttribute.DURATION: _format_timedelta(
self._running_duration
),
TimerEntityStateAttribute.EDITABLE: self.editable,
TimerEntityStateAttribute.LAST_TRANSITION: self._last_transition,
}
if self._end is not None:
attrs[ATTR_FINISHES_AT] = self._end.isoformat()
attrs[TimerEntityStateAttribute.FINISHES_AT] = self._end.isoformat()
if self._remaining is not None:
attrs[ATTR_REMAINING] = _format_timedelta(self._remaining)
attrs[TimerEntityStateAttribute.REMAINING] = _format_timedelta(
self._remaining
)
if self._restore:
attrs[ATTR_RESTORE] = self._restore
attrs[TimerEntityStateAttribute.RESTORE] = self._restore
return attrs
+14
View File
@@ -0,0 +1,14 @@
"""Constants for the timer integration."""
from enum import StrEnum
class TimerEntityStateAttribute(StrEnum):
"""State attributes for timer entities."""
DURATION = "duration"
EDITABLE = "editable"
LAST_TRANSITION = "last_transition"
FINISHES_AT = "finishes_at"
REMAINING = "remaining"
RESTORE = "restore"