|
54 | 54 |
|
55 | 55 | from tests.common import MockConfigEntry, async_fire_time_changed
|
56 | 56 |
|
| 57 | +INITIAL_FETCH_CLIENT_METHODS = [ |
| 58 | + "get_settings", |
| 59 | + "get_status", |
| 60 | + "get_all_programs", |
| 61 | + "get_available_commands", |
| 62 | + "get_available_program", |
| 63 | +] |
| 64 | + |
57 | 65 |
|
58 | 66 | @pytest.fixture
|
59 | 67 | def platforms() -> list[str]:
|
@@ -214,15 +222,32 @@ async def test_coordinator_failure_refresh_and_stream(
|
214 | 222 | assert state.state != STATE_UNAVAILABLE
|
215 | 223 |
|
216 | 224 |
|
| 225 | +@pytest.mark.parametrize( |
| 226 | + "appliance", |
| 227 | + ["Dishwasher"], |
| 228 | + indirect=True, |
| 229 | +) |
| 230 | +async def test_coordinator_not_fetching_on_disconnected_appliance( |
| 231 | + config_entry: MockConfigEntry, |
| 232 | + integration_setup: Callable[[MagicMock], Awaitable[bool]], |
| 233 | + setup_credentials: None, |
| 234 | + client: MagicMock, |
| 235 | + appliance: HomeAppliance, |
| 236 | +) -> None: |
| 237 | + """Test that the coordinator does not fetch anything on disconnected appliance.""" |
| 238 | + appliance.connected = False |
| 239 | + |
| 240 | + assert config_entry.state == ConfigEntryState.NOT_LOADED |
| 241 | + await integration_setup(client) |
| 242 | + assert config_entry.state == ConfigEntryState.LOADED |
| 243 | + |
| 244 | + for method in INITIAL_FETCH_CLIENT_METHODS: |
| 245 | + assert getattr(client, method).call_count == 0 |
| 246 | + |
| 247 | + |
217 | 248 | @pytest.mark.parametrize(
|
218 | 249 | "mock_method",
|
219 |
| - [ |
220 |
| - "get_settings", |
221 |
| - "get_status", |
222 |
| - "get_all_programs", |
223 |
| - "get_available_commands", |
224 |
| - "get_available_program", |
225 |
| - ], |
| 250 | + INITIAL_FETCH_CLIENT_METHODS, |
226 | 251 | )
|
227 | 252 | async def test_coordinator_update_failing(
|
228 | 253 | mock_method: str,
|
@@ -551,3 +576,35 @@ async def test_devices_updated_on_refresh(
|
551 | 576 | assert not device_registry.async_get_device({(DOMAIN, appliances[0].ha_id)})
|
552 | 577 | for appliance in appliances[2:3]:
|
553 | 578 | assert device_registry.async_get_device({(DOMAIN, appliance.ha_id)})
|
| 579 | + |
| 580 | + |
| 581 | +@pytest.mark.parametrize("appliance", ["Washer"], indirect=True) |
| 582 | +async def test_paired_disconnected_devices_not_fetching( |
| 583 | + hass: HomeAssistant, |
| 584 | + config_entry: MockConfigEntry, |
| 585 | + integration_setup: Callable[[MagicMock], Awaitable[bool]], |
| 586 | + setup_credentials: None, |
| 587 | + client: MagicMock, |
| 588 | + appliance: HomeAppliance, |
| 589 | +) -> None: |
| 590 | + """Test that Home Connect API is not fetched after pairing a disconnected device.""" |
| 591 | + client.get_home_appliances = AsyncMock(return_value=ArrayOfHomeAppliances([])) |
| 592 | + assert config_entry.state == ConfigEntryState.NOT_LOADED |
| 593 | + assert await integration_setup(client) |
| 594 | + assert config_entry.state == ConfigEntryState.LOADED |
| 595 | + |
| 596 | + appliance.connected = False |
| 597 | + await client.add_events( |
| 598 | + [ |
| 599 | + EventMessage( |
| 600 | + appliance.ha_id, |
| 601 | + EventType.PAIRED, |
| 602 | + data=ArrayOfEvents([]), |
| 603 | + ) |
| 604 | + ] |
| 605 | + ) |
| 606 | + await hass.async_block_till_done() |
| 607 | + |
| 608 | + client.get_specific_appliance.assert_awaited_once_with(appliance.ha_id) |
| 609 | + for method in INITIAL_FETCH_CLIENT_METHODS: |
| 610 | + assert getattr(client, method).call_count == 0 |
0 commit comments