mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 05:06:13 +01:00
Fix last_reported_timestamp not being updated when last_reported is changed (#118341)
* Reduce number of calls to last_reported_timestamp When a state is created, last_update is always the same as last_reported, and we only update it later if it changes so we can pre-set the cached property to avoid it being run when the recorder accesses it later. * fix cache not being overridden * coverage
This commit is contained in:
@@ -3524,3 +3524,18 @@ async def test_set_time_zone_deprecated(hass: HomeAssistant) -> None:
|
||||
),
|
||||
):
|
||||
await hass.config.set_time_zone("America/New_York")
|
||||
|
||||
|
||||
async def test_async_set_updates_last_reported(hass: HomeAssistant) -> None:
|
||||
"""Test async_set method updates last_reported AND last_reported_timestamp."""
|
||||
hass.states.async_set("light.bowl", "on", {})
|
||||
state = hass.states.get("light.bowl")
|
||||
last_reported = state.last_reported
|
||||
last_reported_timestamp = state.last_reported_timestamp
|
||||
|
||||
for _ in range(2):
|
||||
hass.states.async_set("light.bowl", "on", {})
|
||||
assert state.last_reported != last_reported
|
||||
assert state.last_reported_timestamp != last_reported_timestamp
|
||||
last_reported = state.last_reported
|
||||
last_reported_timestamp = state.last_reported_timestamp
|
||||
|
||||
Reference in New Issue
Block a user