Refactor optimistic update and delayed refresh for Liebherr integration (#163121)

This commit is contained in:
mettolen
2026-02-19 00:11:47 +02:00
committed by GitHub
parent 2e0f727981
commit be25603b76
8 changed files with 64 additions and 63 deletions

View File

@@ -2,6 +2,7 @@
from collections.abc import Generator
import copy
from datetime import timedelta
from unittest.mock import AsyncMock, MagicMock, patch
from pyliebherrhomeapi import (
@@ -86,6 +87,16 @@ MOCK_DEVICE_STATE = DeviceState(
)
@pytest.fixture(autouse=True)
def patch_refresh_delay() -> Generator[None]:
"""Patch REFRESH_DELAY to 0 to avoid delays in tests."""
with patch(
"homeassistant.components.liebherr.entity.REFRESH_DELAY",
timedelta(seconds=0),
):
yield
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""

View File

@@ -172,6 +172,8 @@ async def test_set_temperature(
"""Test setting the temperature."""
entity_id = "number.test_fridge_top_zone_setpoint"
initial_call_count = mock_liebherr_client.get_device_state.call_count
await hass.services.async_call(
NUMBER_DOMAIN,
SERVICE_SET_VALUE,
@@ -186,6 +188,9 @@ async def test_set_temperature(
unit=TemperatureUnit.CELSIUS,
)
# Verify coordinator refresh was triggered
assert mock_liebherr_client.get_device_state.call_count > initial_call_count
@pytest.mark.usefixtures("init_integration")
async def test_set_temperature_failure(
@@ -201,7 +206,7 @@ async def test_set_temperature_failure(
with pytest.raises(
HomeAssistantError,
match="An error occurred while communicating with the device: Connection failed",
match="An error occurred while communicating with the device",
):
await hass.services.async_call(
NUMBER_DOMAIN,

View File

@@ -140,7 +140,7 @@ async def test_switch_failure(
with pytest.raises(
HomeAssistantError,
match="An error occurred while communicating with the device: Connection failed",
match="An error occurred while communicating with the device",
):
await hass.services.async_call(
SWITCH_DOMAIN,