mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Fix LazyState
compatibility with State
under_cached_property
change (#132752)
This commit is contained in:
parent
aa7b69afd4
commit
e4ba94f939
@ -96,6 +96,21 @@ class LazyState(State):
|
|||||||
assert self._last_updated_ts is not None
|
assert self._last_updated_ts is not None
|
||||||
return dt_util.utc_from_timestamp(self._last_updated_ts)
|
return dt_util.utc_from_timestamp(self._last_updated_ts)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def last_updated_timestamp(self) -> float: # type: ignore[override]
|
||||||
|
"""Last updated timestamp."""
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert self._last_updated_ts is not None
|
||||||
|
return self._last_updated_ts
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def last_changed_timestamp(self) -> float: # type: ignore[override]
|
||||||
|
"""Last changed timestamp."""
|
||||||
|
ts = self._last_changed_ts or self._last_updated_ts
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert ts is not None
|
||||||
|
return ts
|
||||||
|
|
||||||
def as_dict(self) -> dict[str, Any]: # type: ignore[override]
|
def as_dict(self) -> dict[str, Any]: # type: ignore[override]
|
||||||
"""Return a dict representation of the LazyState.
|
"""Return a dict representation of the LazyState.
|
||||||
|
|
||||||
|
@ -346,6 +346,8 @@ async def test_lazy_state_handles_different_last_updated_and_last_changed(
|
|||||||
"last_updated": "2021-06-12T03:04:01.000323+00:00",
|
"last_updated": "2021-06-12T03:04:01.000323+00:00",
|
||||||
"state": "off",
|
"state": "off",
|
||||||
}
|
}
|
||||||
|
assert lstate.last_changed_timestamp == row.last_changed_ts
|
||||||
|
assert lstate.last_updated_timestamp == row.last_updated_ts
|
||||||
|
|
||||||
|
|
||||||
async def test_lazy_state_handles_same_last_updated_and_last_changed(
|
async def test_lazy_state_handles_same_last_updated_and_last_changed(
|
||||||
@ -379,3 +381,5 @@ async def test_lazy_state_handles_same_last_updated_and_last_changed(
|
|||||||
"last_updated": "2021-06-12T03:04:01.000323+00:00",
|
"last_updated": "2021-06-12T03:04:01.000323+00:00",
|
||||||
"state": "off",
|
"state": "off",
|
||||||
}
|
}
|
||||||
|
assert lstate.last_changed_timestamp == row.last_changed_ts
|
||||||
|
assert lstate.last_updated_timestamp == row.last_updated_ts
|
||||||
|
Loading…
x
Reference in New Issue
Block a user