mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Calculate _attr_native_value when no restore state and appliance is running in Whirlpool (#88559)
* Initialize _attr_native_value when running * Fix return type on update_sensor_state() move init at startup if _attr_native_value is None * allow update _attr_native_value when running and none
This commit is contained in:
parent
fba826ae9e
commit
bfec3d68dd
@ -290,12 +290,15 @@ class WasherDryerTimeClass(RestoreSensor):
|
||||
|
||||
if machine_state is MachineState.RunningMainCycle:
|
||||
self._running = True
|
||||
|
||||
new_timestamp = now + timedelta(
|
||||
seconds=int(self._wd.get_attribute("Cavity_TimeStatusEstTimeRemaining"))
|
||||
)
|
||||
|
||||
if isinstance(self._attr_native_value, datetime) and abs(
|
||||
new_timestamp - self._attr_native_value
|
||||
) > timedelta(seconds=60):
|
||||
if (
|
||||
isinstance(self._attr_native_value, datetime)
|
||||
and abs(new_timestamp - self._attr_native_value) > timedelta(seconds=60)
|
||||
or self._attr_native_value is None
|
||||
):
|
||||
self._attr_native_value = new_timestamp
|
||||
self._async_write_ha_state()
|
||||
|
@ -17,7 +17,7 @@ async def update_sensor_state(
|
||||
hass: HomeAssistant,
|
||||
entity_id: str,
|
||||
mock_sensor_api_instance: MagicMock,
|
||||
) -> None:
|
||||
) -> State:
|
||||
"""Simulate an update trigger from the API."""
|
||||
|
||||
for call in mock_sensor_api_instance.register_attr_callback.call_args_list:
|
||||
@ -300,6 +300,23 @@ async def test_restore_state(
|
||||
assert state.state == thetimestamp.isoformat()
|
||||
|
||||
|
||||
async def test_no_restore_state(
|
||||
hass: HomeAssistant,
|
||||
mock_sensor_api_instances: MagicMock,
|
||||
mock_sensor1_api: MagicMock,
|
||||
) -> None:
|
||||
"""Test sensor restore state with no restore."""
|
||||
# create and add entry
|
||||
entity_id = "sensor.washer_end_time"
|
||||
await init_integration(hass)
|
||||
# restore from cache
|
||||
state = hass.states.get(entity_id)
|
||||
state.state = "unknown"
|
||||
|
||||
state = await update_sensor_state(hass, entity_id, mock_sensor1_api)
|
||||
state.state = datetime.now().isoformat()
|
||||
|
||||
|
||||
async def test_callback(
|
||||
hass: HomeAssistant,
|
||||
mock_sensor_api_instances: MagicMock,
|
||||
|
Loading…
x
Reference in New Issue
Block a user