Record state.last_reported (#114201)

* Record state.last_reported

* Include last_reported in parts of the history API

* Use a bulk update

* fix refactoring error

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Erik Montnemery 2024-03-27 12:48:06 +01:00 committed by GitHub
parent 24168dfba7
commit a3059fe504
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 225 additions and 23 deletions

View file

@ -81,6 +81,18 @@ class LazyState(State):
self._last_changed_ts or self._last_updated_ts
)
@cached_property
def _last_reported_ts(self) -> float | None:
"""Last reported timestamp."""
return getattr(self._row, "last_reported_ts", None)
@cached_property
def last_reported(self) -> datetime: # type: ignore[override]
"""Last reported datetime."""
return dt_util.utc_from_timestamp(
self._last_reported_ts or self._last_updated_ts
)
@cached_property
def last_updated(self) -> datetime: # type: ignore[override]
"""Last updated datetime."""