Skip to content

Commit 883ab44

Browse files
authored
Move Home Connect entry state assertion at tests (#144027)
1 parent abd17d9 commit 883ab44

14 files changed

+2
-94
lines changed

tests/components/home_connect/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
async_import_client_credential,
3737
)
3838
from homeassistant.components.home_connect.const import DOMAIN
39+
from homeassistant.config_entries import ConfigEntryState
3940
from homeassistant.const import Platform
4041
from homeassistant.core import HomeAssistant
4142
from homeassistant.setup import async_setup_component
@@ -147,6 +148,7 @@ async def mock_integration_setup(
147148
config_entry.add_to_hass(hass)
148149

149150
async def run(client: MagicMock) -> bool:
151+
assert config_entry.state is ConfigEntryState.NOT_LOADED
150152
with (
151153
patch("homeassistant.components.home_connect.PLATFORMS", platforms),
152154
patch(

tests/components/home_connect/test_binary_sensor.py

-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ async def test_paired_depaired_devices_flow(
5151
appliance: HomeAppliance,
5252
) -> None:
5353
"""Test that removed devices are correctly removed from and added to hass on API events."""
54-
assert config_entry.state == ConfigEntryState.NOT_LOADED
5554
assert await integration_setup(client)
5655
assert config_entry.state == ConfigEntryState.LOADED
5756

@@ -128,7 +127,6 @@ def get_status_side_effect(ha_id: str):
128127
return get_status_original_mock.return_value
129128

130129
client.get_status = AsyncMock(side_effect=get_status_side_effect)
131-
assert config_entry.state == ConfigEntryState.NOT_LOADED
132130
assert await integration_setup(client)
133131
assert config_entry.state == ConfigEntryState.LOADED
134132
client.get_status = get_status_original_mock
@@ -179,7 +177,6 @@ async def test_binary_sensors_entity_availability(
179177
entity_ids = [
180178
"binary_sensor.washer_remote_control",
181179
]
182-
assert config_entry.state == ConfigEntryState.NOT_LOADED
183180
assert await integration_setup(client)
184181
assert config_entry.state == ConfigEntryState.LOADED
185182

@@ -279,7 +276,6 @@ async def test_binary_sensors_functionality(
279276
expected: str,
280277
) -> None:
281278
"""Tests for Home Connect Fridge appliance door states."""
282-
assert config_entry.state == ConfigEntryState.NOT_LOADED
283279
assert await integration_setup(client)
284280
assert config_entry.state == ConfigEntryState.LOADED
285281
await client.add_events(
@@ -316,7 +312,6 @@ async def test_connected_sensor_functionality(
316312
) -> None:
317313
"""Test if the connected binary sensor reports the right values."""
318314
entity_id = "binary_sensor.washer_connectivity"
319-
assert config_entry.state == ConfigEntryState.NOT_LOADED
320315
assert await integration_setup(client)
321316
assert config_entry.state == ConfigEntryState.LOADED
322317

tests/components/home_connect/test_button.py

-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ async def test_paired_depaired_devices_flow(
4343
appliance: HomeAppliance,
4444
) -> None:
4545
"""Test that removed devices are correctly removed from and added to hass on API events."""
46-
assert config_entry.state == ConfigEntryState.NOT_LOADED
4746
assert await integration_setup(client)
4847
assert config_entry.state == ConfigEntryState.LOADED
4948

@@ -131,7 +130,6 @@ async def get_all_programs_side_effect(ha_id: str):
131130
side_effect=get_available_commands_side_effect
132131
)
133132
client.get_all_programs = AsyncMock(side_effect=get_all_programs_side_effect)
134-
assert config_entry.state == ConfigEntryState.NOT_LOADED
135133
assert await integration_setup(client)
136134
assert config_entry.state == ConfigEntryState.LOADED
137135
client.get_available_commands = get_available_commands_original_mock
@@ -183,7 +181,6 @@ async def test_button_entity_availability(
183181
"button.washer_pause_program",
184182
"button.washer_stop_program",
185183
]
186-
assert config_entry.state == ConfigEntryState.NOT_LOADED
187184
assert await integration_setup(client)
188185
assert config_entry.state == ConfigEntryState.LOADED
189186

@@ -246,7 +243,6 @@ async def test_button_functionality(
246243
appliance: HomeAppliance,
247244
) -> None:
248245
"""Test if button entities availability are based on the appliance connection state."""
249-
assert config_entry.state == ConfigEntryState.NOT_LOADED
250246
assert await integration_setup(client)
251247
assert config_entry.state == ConfigEntryState.LOADED
252248

@@ -282,7 +278,6 @@ async def test_command_button_exception(
282278
]
283279
)
284280
)
285-
assert config_entry.state == ConfigEntryState.NOT_LOADED
286281
assert await integration_setup(client_with_exception)
287282
assert config_entry.state == ConfigEntryState.LOADED
288283

@@ -308,7 +303,6 @@ async def test_stop_program_button_exception(
308303
"""Test if button entities availability are based on the appliance connection state."""
309304
entity_id = "button.washer_stop_program"
310305

311-
assert config_entry.state == ConfigEntryState.NOT_LOADED
312306
assert await integration_setup(client_with_exception)
313307
assert config_entry.state == ConfigEntryState.LOADED
314308

tests/components/home_connect/test_coordinator.py

-10
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ async def test_coordinator_not_fetching_on_disconnected_appliance(
218218
"""Test that the coordinator does not fetch anything on disconnected appliance."""
219219
appliance.connected = False
220220

221-
assert config_entry.state == ConfigEntryState.NOT_LOADED
222221
await integration_setup(client)
223222
assert config_entry.state == ConfigEntryState.LOADED
224223

@@ -242,7 +241,6 @@ async def test_coordinator_update_failing(
242241
"""
243242
setattr(client, mock_method, AsyncMock(side_effect=HomeConnectError()))
244243

245-
assert config_entry.state == ConfigEntryState.NOT_LOADED
246244
await integration_setup(client)
247245
assert config_entry.state == ConfigEntryState.LOADED
248246

@@ -286,7 +284,6 @@ async def test_event_listener(
286284
entity_id: str,
287285
) -> None:
288286
"""Test that the event listener works."""
289-
assert config_entry.state == ConfigEntryState.NOT_LOADED
290287
await integration_setup(client)
291288
assert config_entry.state == ConfigEntryState.LOADED
292289

@@ -353,7 +350,6 @@ async def tests_receive_setting_and_status_for_first_time_at_events(
353350
client.get_setting = AsyncMock(return_value=ArrayOfSettings([]))
354351
client.get_status = AsyncMock(return_value=ArrayOfStatus([]))
355352

356-
assert config_entry.state == ConfigEntryState.NOT_LOADED
357353
await integration_setup(client)
358354
assert config_entry.state == ConfigEntryState.LOADED
359355

@@ -468,7 +464,6 @@ async def stream_exception():
468464
side_effect=[stream_exception(), client.stream_all_events()]
469465
)
470466

471-
assert config_entry.state == ConfigEntryState.NOT_LOADED
472467
await integration_setup(client)
473468
await hass.async_block_till_done()
474469

@@ -531,7 +526,6 @@ async def test_devices_updated_on_refresh(
531526
)
532527

533528
await async_setup_component(hass, HA_DOMAIN, {})
534-
assert config_entry.state == ConfigEntryState.NOT_LOADED
535529
await integration_setup(client)
536530
assert config_entry.state == ConfigEntryState.LOADED
537531

@@ -564,7 +558,6 @@ async def test_paired_disconnected_devices_not_fetching(
564558
) -> None:
565559
"""Test that Home Connect API is not fetched after pairing a disconnected device."""
566560
client.get_home_appliances = AsyncMock(return_value=ArrayOfHomeAppliances([]))
567-
assert config_entry.state == ConfigEntryState.NOT_LOADED
568561
assert await integration_setup(client)
569562
assert config_entry.state == ConfigEntryState.LOADED
570563

@@ -601,7 +594,6 @@ async def test_coordinator_disabling_updates_for_appliance(
601594
appliance_ha_id = "SIEMENS-HCS02DWH1-6BE58C26DCC1"
602595
issue_id = f"home_connect_too_many_connected_paired_events_{appliance_ha_id}"
603596

604-
assert config_entry.state == ConfigEntryState.NOT_LOADED
605597
assert await integration_setup(client)
606598
assert config_entry.state == ConfigEntryState.LOADED
607599

@@ -692,7 +684,6 @@ async def test_coordinator_disabling_updates_for_appliance_is_gone_after_entry_r
692684
appliance_ha_id = "SIEMENS-HCS02DWH1-6BE58C26DCC1"
693685
issue_id = f"home_connect_too_many_connected_paired_events_{appliance_ha_id}"
694686

695-
assert config_entry.state == ConfigEntryState.NOT_LOADED
696687
assert await integration_setup(client)
697688
assert config_entry.state == ConfigEntryState.LOADED
698689

@@ -718,7 +709,6 @@ async def test_coordinator_disabling_updates_for_appliance_is_gone_after_entry_r
718709

719710
assert not issue_registry.async_get_issue(DOMAIN, issue_id)
720711

721-
assert config_entry.state == ConfigEntryState.NOT_LOADED
722712
assert await integration_setup(client)
723713
assert config_entry.state == ConfigEntryState.LOADED
724714

tests/components/home_connect/test_diagnostics.py

-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ async def test_async_get_config_entry_diagnostics(
2525
snapshot: SnapshotAssertion,
2626
) -> None:
2727
"""Test config entry diagnostics."""
28-
assert config_entry.state == ConfigEntryState.NOT_LOADED
2928
assert await integration_setup(client)
3029
assert config_entry.state == ConfigEntryState.LOADED
3130

@@ -41,7 +40,6 @@ async def test_async_get_device_diagnostics(
4140
snapshot: SnapshotAssertion,
4241
) -> None:
4342
"""Test device config entry diagnostics."""
44-
assert config_entry.state == ConfigEntryState.NOT_LOADED
4543
assert await integration_setup(client)
4644
assert config_entry.state == ConfigEntryState.LOADED
4745

tests/components/home_connect/test_entity.py

-4
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ async def get_all_programs_with_options_mock(ha_id: str) -> ArrayOfPrograms:
157157
)
158158
)
159159

160-
assert config_entry.state == ConfigEntryState.NOT_LOADED
161160
assert await integration_setup(client)
162161
assert config_entry.state == ConfigEntryState.LOADED
163162

@@ -276,7 +275,6 @@ async def get_all_programs_with_options_mock(ha_id: str) -> ArrayOfPrograms:
276275

277276
client.get_all_programs = AsyncMock(side_effect=get_all_programs_with_options_mock)
278277

279-
assert config_entry.state == ConfigEntryState.NOT_LOADED
280278
assert await integration_setup(client)
281279
assert config_entry.state == ConfigEntryState.LOADED
282280

@@ -357,7 +355,6 @@ async def get_home_appliances_with_options_mock() -> ArrayOfHomeAppliances:
357355
)
358356
)
359357

360-
assert config_entry.state == ConfigEntryState.NOT_LOADED
361358
assert await integration_setup(client)
362359
assert config_entry.state == ConfigEntryState.LOADED
363360

@@ -469,7 +466,6 @@ async def test_option_entity_functionality_exception(
469466
)
470467
)
471468

472-
assert config_entry.state == ConfigEntryState.NOT_LOADED
473469
assert await integration_setup(client)
474470
assert config_entry.state == ConfigEntryState.LOADED
475471

tests/components/home_connect/test_init.py

-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ async def test_entry_setup(
4646
integration_setup: Callable[[MagicMock], Awaitable[bool]],
4747
) -> None:
4848
"""Test setup and unload."""
49-
assert config_entry.state == ConfigEntryState.NOT_LOADED
5049
assert await integration_setup(client)
5150
assert config_entry.state == ConfigEntryState.LOADED
5251

@@ -182,7 +181,6 @@ async def test_client_error(
182181
"""Test client errors during setup integration."""
183182
client_with_exception.get_home_appliances.return_value = None
184183
client_with_exception.get_home_appliances.side_effect = exception
185-
assert config_entry.state == ConfigEntryState.NOT_LOADED
186184
assert not await integration_setup(client_with_exception)
187185
assert config_entry.state == expected_state
188186
assert client_with_exception.get_home_appliances.call_count == 1
@@ -239,7 +237,6 @@ async def test_required_program_or_at_least_an_option(
239237
) -> None:
240238
"Test that the set_program_and_options does raise an exception if no program nor options are set."
241239

242-
assert config_entry.state == ConfigEntryState.NOT_LOADED
243240
assert await integration_setup(client)
244241
assert config_entry.state == ConfigEntryState.LOADED
245242

tests/components/home_connect/test_light.py

-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ async def test_paired_depaired_devices_flow(
6464
appliance: HomeAppliance,
6565
) -> None:
6666
"""Test that removed devices are correctly removed from and added to hass on API events."""
67-
assert config_entry.state == ConfigEntryState.NOT_LOADED
6867
assert await integration_setup(client)
6968
assert config_entry.state == ConfigEntryState.LOADED
7069

@@ -141,7 +140,6 @@ async def get_settings_side_effect(ha_id: str):
141140
return await get_settings_original_mock.side_effect(ha_id)
142141

143142
client.get_settings = AsyncMock(side_effect=get_settings_side_effect)
144-
assert config_entry.state == ConfigEntryState.NOT_LOADED
145143
assert await integration_setup(client)
146144
assert config_entry.state == ConfigEntryState.LOADED
147145
client.get_settings = get_settings_original_mock
@@ -186,7 +184,6 @@ async def test_light_availability(
186184
entity_ids = [
187185
"light.hood_functional_light",
188186
]
189-
assert config_entry.state == ConfigEntryState.NOT_LOADED
190187
assert await integration_setup(client)
191188
assert config_entry.state == ConfigEntryState.LOADED
192189

@@ -353,7 +350,6 @@ async def test_light_functionality(
353350
appliance: HomeAppliance,
354351
) -> None:
355352
"""Test light functionality."""
356-
assert config_entry.state == ConfigEntryState.NOT_LOADED
357353
assert await integration_setup(client)
358354
assert config_entry.state == ConfigEntryState.LOADED
359355

@@ -405,7 +401,6 @@ async def test_light_color_different_than_custom(
405401
appliance: HomeAppliance,
406402
) -> None:
407403
"""Test that light color attributes are not set if color is different than custom."""
408-
assert config_entry.state == ConfigEntryState.NOT_LOADED
409404
assert await integration_setup(client)
410405
assert config_entry.state == ConfigEntryState.LOADED
411406
await hass.services.async_call(
@@ -586,7 +581,6 @@ async def test_light_exception_handling(
586581
client_with_exception.set_setting.side_effect = [
587582
exception() if exception else None for exception in attr_side_effect
588583
]
589-
assert config_entry.state == ConfigEntryState.NOT_LOADED
590584
assert await integration_setup(client_with_exception)
591585
assert config_entry.state == ConfigEntryState.LOADED
592586

tests/components/home_connect/test_number.py

-7
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ async def test_paired_depaired_devices_flow(
8080
],
8181
)
8282
)
83-
assert config_entry.state == ConfigEntryState.NOT_LOADED
8483
assert await integration_setup(client)
8584
assert config_entry.state == ConfigEntryState.LOADED
8685

@@ -159,7 +158,6 @@ def get_settings_side_effect(ha_id: str):
159158
return get_settings_original_mock.return_value
160159

161160
client.get_settings = AsyncMock(side_effect=get_settings_side_effect)
162-
assert config_entry.state == ConfigEntryState.NOT_LOADED
163161
assert await integration_setup(client)
164162
assert config_entry.state == ConfigEntryState.LOADED
165163
client.get_settings = get_settings_original_mock
@@ -209,7 +207,6 @@ async def test_number_entity_availability(
209207
# Setting constrains are not needed for this test
210208
# so we rise an error to easily test the availability
211209
client.get_setting = AsyncMock(side_effect=HomeConnectError())
212-
assert config_entry.state == ConfigEntryState.NOT_LOADED
213210
assert await integration_setup(client)
214211
assert config_entry.state == ConfigEntryState.LOADED
215212

@@ -316,7 +313,6 @@ async def test_number_entity_functionality(
316313
)
317314
)
318315

319-
assert config_entry.state is ConfigEntryState.NOT_LOADED
320316
assert await integration_setup(client)
321317
assert config_entry.state is ConfigEntryState.LOADED
322318
entity_state = hass.states.get(entity_id)
@@ -420,7 +416,6 @@ def get_settings_side_effect(ha_id: str):
420416
]
421417
)
422418

423-
assert config_entry.state is ConfigEntryState.NOT_LOADED
424419
assert await integration_setup(client)
425420
async_fire_time_changed(hass)
426421
await hass.async_block_till_done()
@@ -472,7 +467,6 @@ async def test_number_entity_error(
472467
)
473468
]
474469
)
475-
assert config_entry.state is ConfigEntryState.NOT_LOADED
476470
assert await integration_setup(client_with_exception)
477471
assert config_entry.state is ConfigEntryState.LOADED
478472

@@ -599,7 +593,6 @@ async def set_program_option_side_effect(ha_id: str, *_, **kwargs) -> None:
599593
)
600594
)
601595

602-
assert config_entry.state == ConfigEntryState.NOT_LOADED
603596
assert await integration_setup(client)
604597
assert config_entry.state == ConfigEntryState.LOADED
605598
entity_state = hass.states.get(entity_id)

0 commit comments

Comments
 (0)