From 1c8d96183297d119e5355fb0fdf6ad38b0ddf717 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 23 Dec 2023 00:11:14 -1000 Subject: [PATCH] Add support for attribute caching to ToggleEntity (#106272) --- homeassistant/helpers/entity.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 4fa2d5c3e51..95d003cd11c 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -1496,7 +1496,12 @@ class ToggleEntityDescription(EntityDescription, frozen_or_thawed=True): """A class that describes toggle entities.""" -class ToggleEntity(Entity): +TOGGLE_ENTITY_CACHED_PROPERTIES_WITH_ATTR_ = {"is_on"} + + +class ToggleEntity( + Entity, cached_properties=TOGGLE_ENTITY_CACHED_PROPERTIES_WITH_ATTR_ +): """An abstract class for entities that can be turned on and off.""" entity_description: ToggleEntityDescription @@ -1511,7 +1516,7 @@ class ToggleEntity(Entity): return None return STATE_ON if is_on else STATE_OFF - @property + @cached_property def is_on(self) -> bool | None: """Return True if entity is on.""" return self._attr_is_on