mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Store sensor last_reset attribute as a string, not a datetime (#50851)
* Store last_reset attribute as a string, not a datetime * Update tests
This commit is contained in:
parent
7573adda7f
commit
5ee362bc34
@ -119,6 +119,6 @@ class SensorEntity(Entity):
|
||||
def state_attributes(self) -> dict[str, Any] | None:
|
||||
"""Return state attributes."""
|
||||
if last_reset := self.last_reset:
|
||||
return {ATTR_LAST_RESET: last_reset}
|
||||
return {ATTR_LAST_RESET: last_reset.isoformat()}
|
||||
|
||||
return None
|
||||
|
@ -200,12 +200,12 @@ async def test_restore_state(hass):
|
||||
state = hass.states.get("sensor.energy_bill_onpeak")
|
||||
assert state.state == "3"
|
||||
assert state.attributes.get("status") == PAUSED
|
||||
assert state.attributes.get("last_reset") == dt_util.parse_datetime(last_reset)
|
||||
assert state.attributes.get("last_reset") == last_reset
|
||||
|
||||
state = hass.states.get("sensor.energy_bill_offpeak")
|
||||
assert state.state == "6"
|
||||
assert state.attributes.get("status") == COLLECTING
|
||||
assert state.attributes.get("last_reset") == dt_util.parse_datetime(last_reset)
|
||||
assert state.attributes.get("last_reset") == last_reset
|
||||
|
||||
# utility_meter is loaded, now set sensors according to utility_meter:
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
@ -348,12 +348,13 @@ async def _test_self_reset(hass, config, start_time, expect_reset=True):
|
||||
state = hass.states.get("sensor.energy_bill")
|
||||
if expect_reset:
|
||||
assert state.attributes.get("last_period") == "2"
|
||||
assert state.attributes.get("last_reset") == now
|
||||
assert state.attributes.get("last_reset") == now.isoformat()
|
||||
assert state.state == "3"
|
||||
else:
|
||||
assert state.attributes.get("last_period") == 0
|
||||
assert state.state == "5"
|
||||
assert state.attributes.get("last_reset") == dt_util.parse_datetime(start_time)
|
||||
start_time_str = dt_util.parse_datetime(start_time).isoformat()
|
||||
assert state.attributes.get("last_reset") == start_time_str
|
||||
|
||||
|
||||
async def test_self_reset_quarter_hourly(hass, legacy_patchable_time):
|
||||
|
Loading…
x
Reference in New Issue
Block a user