Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate _attr_native_value when no restore state and appliance is running in Whirlpool #88559

Merged
merged 10 commits into from
May 31, 2023
2 changes: 2 additions & 0 deletions homeassistant/components/whirlpool/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def __init__(
)
self._attr_has_entity_name = True
self._attr_unique_id = f"{said}-{description.key}"
if self._attr_native_value is None:
self._attr_native_value = utcnow()
mkmer marked this conversation as resolved.
Show resolved Hide resolved

async def async_added_to_hass(self) -> None:
"""Connect washer/dryer to the cloud."""
Expand Down
16 changes: 15 additions & 1 deletion tests/components/whirlpool/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -299,6 +299,20 @@ 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 = datetime.now().isoformat()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too?



async def test_callback(
hass: HomeAssistant,
mock_sensor_api_instances: MagicMock,
Expand Down