From a6f869aeee67705967a11f54c84f9b4b998e239f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 9 Aug 2020 06:45:16 -0500 Subject: [PATCH] Improve performance of fetching the state domain (#38653) Pre calc domain when an entity id created to avoid having to call the property method which had to call split_entity_id every time. If there are a lot of zone related automations, async_active_zone can call async_entity_ids frequently which results in 100000s of split_entity_id via the domain property every second. --- homeassistant/core.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index da40c17c411..14699aba33e 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -759,6 +759,7 @@ class State: last_changed: last time the state was changed, not the attributes. last_updated: last time this object was updated. context: Context in which it was created + domain: Domain of this state. """ __slots__ = [ @@ -768,6 +769,7 @@ class State: "last_changed", "last_updated", "context", + "domain", ] def __init__( @@ -801,11 +803,7 @@ class State: self.last_updated = last_updated or dt_util.utcnow() self.last_changed = last_changed or self.last_updated self.context = context or Context() - - @property - def domain(self) -> str: - """Domain of this state.""" - return split_entity_id(self.entity_id)[0] + self.domain = split_entity_id(self.entity_id)[0] @property def object_id(self) -> str: