From bf16f6b104793b730c3d3441ae4cebcd5f24d748 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 16 May 2023 12:39:16 -0500 Subject: [PATCH] Remove as_compressed_state cache (#93169) * Remove as_compressed_state cache All calls to as_compressed_state are now covered by a higher level JSON cache so there is no need to store these in memory anymore * Remove as_compressed_state cache All calls to as_compressed_state are now covered by a higher level JSON cache so there is no need to store these in memory anymore --- homeassistant/core.py | 5 ----- tests/test_core.py | 2 -- 2 files changed, 7 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 9560d0f1031..2806907f19f 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1224,7 +1224,6 @@ class State: "domain", "object_id", "_as_dict", - "_as_compressed_state", "_as_dict_json", "_as_compressed_state_json", ) @@ -1262,7 +1261,6 @@ class State: self.context = context or Context() self.domain, self.object_id = split_entity_id(self.entity_id) self._as_dict: ReadOnlyDict[str, Collection[Any]] | None = None - self._as_compressed_state: dict[str, Any] | None = None self._as_dict_json: str | None = None self._as_compressed_state_json: str | None = None @@ -1312,8 +1310,6 @@ class State: Sends c (context) as a string if it only contains an id. """ - if self._as_compressed_state: - return self._as_compressed_state state_context = self.context if state_context.parent_id is None and state_context.user_id is None: context: dict[str, Any] | str = state_context.id @@ -1329,7 +1325,6 @@ class State: compressed_state[COMPRESSED_STATE_LAST_UPDATED] = dt_util.utc_to_timestamp( self.last_updated ) - self._as_compressed_state = compressed_state return compressed_state def as_compressed_state_json(self) -> str: diff --git a/tests/test_core.py b/tests/test_core.py index f9fdf6284c0..5cb92ffe5c9 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -511,7 +511,6 @@ def test_state_as_compressed_state() -> None: assert as_compressed_state == expected # 2nd time to verify cache assert state.as_compressed_state() == expected - assert state.as_compressed_state() is as_compressed_state def test_state_as_compressed_state_unique_last_updated() -> None: @@ -538,7 +537,6 @@ def test_state_as_compressed_state_unique_last_updated() -> None: assert as_compressed_state == expected # 2nd time to verify cache assert state.as_compressed_state() == expected - assert state.as_compressed_state() is as_compressed_state def test_state_as_compressed_state_json() -> None: