mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 03:03:17 +01:00
Refactor optimistic update and delayed refresh for Liebherr integration (#163121)
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user