Improve isoformat timestamp performance for full states (#37105)
This commit is contained in:
parent
fd1a8dd96c
commit
30df871787
1 changed files with 27 additions and 0 deletions
|
@ -669,6 +669,33 @@ class LazyState(State):
|
||||||
"""Set last updated datetime."""
|
"""Set last updated datetime."""
|
||||||
self._last_updated = value
|
self._last_updated = value
|
||||||
|
|
||||||
|
def as_dict(self):
|
||||||
|
"""Return a dict representation of the LazyState.
|
||||||
|
|
||||||
|
Async friendly.
|
||||||
|
|
||||||
|
To be used for JSON serialization.
|
||||||
|
"""
|
||||||
|
if self._last_changed:
|
||||||
|
last_changed_isoformat = self._last_changed.isoformat()
|
||||||
|
else:
|
||||||
|
last_changed_isoformat = process_timestamp_to_utc_isoformat(
|
||||||
|
self._row.last_changed
|
||||||
|
)
|
||||||
|
if self._last_updated:
|
||||||
|
last_updated_isoformat = self._last_updated.isoformat()
|
||||||
|
else:
|
||||||
|
last_updated_isoformat = process_timestamp_to_utc_isoformat(
|
||||||
|
self._row.last_updated
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"entity_id": self.entity_id,
|
||||||
|
"state": self.state,
|
||||||
|
"attributes": self._attributes or self.attributes,
|
||||||
|
"last_changed": last_changed_isoformat,
|
||||||
|
"last_updated": last_updated_isoformat,
|
||||||
|
}
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
"""Return the comparison."""
|
"""Return the comparison."""
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue