mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add support for attribute caching to ToggleEntity (#106272)
This commit is contained in:
parent
ca7daa21fe
commit
1c8d961832
@ -1496,7 +1496,12 @@ class ToggleEntityDescription(EntityDescription, frozen_or_thawed=True):
|
|||||||
"""A class that describes toggle entities."""
|
"""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."""
|
"""An abstract class for entities that can be turned on and off."""
|
||||||
|
|
||||||
entity_description: ToggleEntityDescription
|
entity_description: ToggleEntityDescription
|
||||||
@ -1511,7 +1516,7 @@ class ToggleEntity(Entity):
|
|||||||
return None
|
return None
|
||||||
return STATE_ON if is_on else STATE_OFF
|
return STATE_ON if is_on else STATE_OFF
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def is_on(self) -> bool | None:
|
def is_on(self) -> bool | None:
|
||||||
"""Return True if entity is on."""
|
"""Return True if entity is on."""
|
||||||
return self._attr_is_on
|
return self._attr_is_on
|
||||||
|
Loading…
x
Reference in New Issue
Block a user