Make creation of capabilities_updated_at deque in Entity lazy (#114711)
Most entities will never update their capabilities so we should avoid creating the deque as its a large chunk of the entity creation time
This commit is contained in:
parent
b9f27d2b31
commit
2b9f22f11e
1 changed files with 10 additions and 3 deletions
|
@ -1131,7 +1131,16 @@ class Entity(
|
|||
):
|
||||
if not self.__capabilities_updated_at_reported:
|
||||
time_now = hass.loop.time()
|
||||
capabilities_updated_at = self.__capabilities_updated_at
|
||||
# _Entity__capabilities_updated_at is because of name mangling
|
||||
if not (
|
||||
capabilities_updated_at := getattr(
|
||||
self, "_Entity__capabilities_updated_at", None
|
||||
)
|
||||
):
|
||||
self.__capabilities_updated_at = deque(
|
||||
maxlen=CAPABILITIES_UPDATE_LIMIT + 1
|
||||
)
|
||||
capabilities_updated_at = self.__capabilities_updated_at
|
||||
capabilities_updated_at.append(time_now)
|
||||
while time_now - capabilities_updated_at[0] > 3600:
|
||||
capabilities_updated_at.popleft()
|
||||
|
@ -1444,8 +1453,6 @@ class Entity(
|
|||
)
|
||||
self._async_subscribe_device_updates()
|
||||
|
||||
self.__capabilities_updated_at = deque(maxlen=CAPABILITIES_UPDATE_LIMIT + 1)
|
||||
|
||||
async def async_internal_will_remove_from_hass(self) -> None:
|
||||
"""Run when entity will be removed from hass.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue