diff --git a/homeassistant/core.py b/homeassistant/core.py index 73d0e82fa83..40d6a544713 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1790,6 +1790,12 @@ class State: self.context = context or Context() self.state_info = state_info self.domain, self.object_id = split_entity_id(self.entity_id) + # The recorder or the websocket_api will always call the timestamps, + # so we will set the timestamp values here to avoid the overhead of + # the function call in the property we know will always be called. + self.last_updated_timestamp = self.last_updated.timestamp() + if self.last_changed == self.last_updated: + self.__dict__["last_changed_timestamp"] = self.last_updated_timestamp @cached_property def name(self) -> str: @@ -1801,8 +1807,6 @@ class State: @cached_property def last_changed_timestamp(self) -> float: """Timestamp of last change.""" - if self.last_changed == self.last_updated: - return self.last_updated_timestamp return self.last_changed.timestamp() @cached_property @@ -1812,11 +1816,6 @@ class State: return self.last_updated_timestamp return self.last_reported.timestamp() - @cached_property - def last_updated_timestamp(self) -> float: - """Timestamp of last update.""" - return self.last_updated.timestamp() - @cached_property def _as_dict(self) -> dict[str, Any]: """Return a dict representation of the State.