From b311fe2a0f6ff6de263cf5fb0fbef623d3304b0c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 20 Mar 2024 13:41:24 -1000 Subject: [PATCH] Reduce overhead to clear cache in button state (#113895) Same optimization as #113136 --- homeassistant/components/button/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/button/__init__.py b/homeassistant/components/button/__init__.py index 6826f681d4d..10589aa461f 100644 --- a/homeassistant/components/button/__init__.py +++ b/homeassistant/components/button/__init__.py @@ -123,10 +123,8 @@ class ButtonEntity(RestoreEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_ def __set_state(self, state: str | None) -> None: """Set the entity state.""" - try: # noqa: SIM105 suppress is much slower - del self.state - except AttributeError: - pass + # Invalidate the cache of the cached property + self.__dict__.pop("state", None) self.__last_pressed_isoformat = state @final