Skip to content

Commit

Permalink
Add support for attribute caching to ToggleEntity (#106272)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Dec 23, 2023
1 parent ca7daa2 commit 1c8d961
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions homeassistant/helpers/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1511,7 +1516,7 @@ def state(self) -> Literal["on", "off"] | None:
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
Expand Down

0 comments on commit 1c8d961

Please sign in to comment.