diff --git a/tests/components/zwave_js/test_config_flow.py b/tests/components/zwave_js/test_config_flow.py index fd26783e419..e07caca3c6a 100644 --- a/tests/components/zwave_js/test_config_flow.py +++ b/tests/components/zwave_js/test_config_flow.py @@ -87,6 +87,31 @@ def platforms() -> list[str]: return [] +@pytest.fixture(name="discovery_info", autouse=True) +def discovery_info_fixture() -> list[Discovery]: + """Fixture to set up discovery info.""" + return [ + Discovery( + addon="core_zwave_js", + service="zwave_js", + uuid=uuid4(), + config=ADDON_DISCOVERY_INFO, + ) + ] + + +@pytest.fixture(name="discovery_info_side_effect", autouse=True) +def discovery_info_side_effect_fixture() -> Any | None: + """Return the discovery info from the supervisor.""" + return None + + +@pytest.fixture(name="get_addon_discovery_info", autouse=True) +def get_addon_discovery_info_fixture(get_addon_discovery_info: AsyncMock) -> AsyncMock: + """Get add-on discovery info.""" + return get_addon_discovery_info + + @pytest.fixture(name="setup_entry") def setup_entry_fixture() -> Generator[AsyncMock]: """Mock entry setup.""" @@ -226,6 +251,7 @@ async def slow_server_version(*args): await asyncio.sleep(0.1) +@pytest.mark.usefixtures("integration") @pytest.mark.parametrize( ("url", "server_version_side_effect", "server_version_timeout", "error"), [ @@ -249,7 +275,7 @@ async def slow_server_version(*args): ), ], ) -async def test_manual_errors(hass: HomeAssistant, integration, url, error) -> None: +async def test_manual_errors(hass: HomeAssistant, url: str, error: str) -> None: """Test all errors with a manual set up.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -293,7 +319,10 @@ async def test_manual_errors(hass: HomeAssistant, integration, url, error) -> No ], ) async def test_reconfigure_manual_errors( - hass: HomeAssistant, integration, url, error + hass: HomeAssistant, + integration: MockConfigEntry, + url: str, + error: str, ) -> None: """Test all errors with a manual set up in a reconfigure flow.""" entry = integration @@ -354,13 +383,10 @@ async def test_manual_already_configured(hass: HomeAssistant) -> None: assert entry.data["integration_created_addon"] is False -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) +@pytest.mark.usefixtures("supervisor", "addon_running") async def test_supervisor_discovery( hass: HomeAssistant, - supervisor, - addon_running, - addon_options, - get_addon_discovery_info, + addon_options: dict[str, Any], ) -> None: """Test flow started from Supervisor discovery.""" @@ -413,13 +439,9 @@ async def test_supervisor_discovery( assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.parametrize( - ("discovery_info", "server_version_side_effect"), - [({"config": ADDON_DISCOVERY_INFO}, TimeoutError())], -) -async def test_supervisor_discovery_cannot_connect( - hass: HomeAssistant, supervisor, get_addon_discovery_info -) -> None: +@pytest.mark.usefixtures("supervisor") +@pytest.mark.parametrize("server_version_side_effect", [TimeoutError()]) +async def test_supervisor_discovery_cannot_connect(hass: HomeAssistant) -> None: """Test Supervisor discovery and cannot connect.""" result = await hass.config_entries.flow.async_init( @@ -437,13 +459,11 @@ async def test_supervisor_discovery_cannot_connect( assert result["reason"] == "cannot_connect" -@pytest.mark.parametrize("discovery_info", [{"config": ADDON_DISCOVERY_INFO}]) async def test_clean_discovery_on_user_create( hass: HomeAssistant, supervisor, addon_running, addon_options, - get_addon_discovery_info, ) -> None: """Test discovery flow is cleaned up when a user flow is finished.""" @@ -525,8 +545,10 @@ async def test_clean_discovery_on_user_create( assert len(mock_setup_entry.mock_calls) == 1 +@pytest.mark.usefixtures("supervisor", "addon_running") async def test_abort_discovery_with_existing_entry( - hass: HomeAssistant, supervisor, addon_running, addon_options + hass: HomeAssistant, + addon_options: dict[str, Any], ) -> None: """Test discovery flow is aborted if an entry already exists.""" @@ -555,9 +577,8 @@ async def test_abort_discovery_with_existing_entry( assert entry.data["url"] == "ws://host1:3001" -async def test_abort_hassio_discovery_with_existing_flow( - hass: HomeAssistant, supervisor, addon_installed, addon_options -) -> None: +@pytest.mark.usefixtures("supervisor", "addon_installed", "addon_info") +async def test_abort_hassio_discovery_with_existing_flow(hass: HomeAssistant) -> None: """Test hassio discovery flow is aborted when another discovery has happened.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -582,9 +603,8 @@ async def test_abort_hassio_discovery_with_existing_flow( assert result2["reason"] == "already_in_progress" -async def test_abort_hassio_discovery_for_other_addon( - hass: HomeAssistant, supervisor, addon_installed, addon_options -) -> None: +@pytest.mark.usefixtures("supervisor", "addon_installed", "addon_info") +async def test_abort_hassio_discovery_for_other_addon(hass: HomeAssistant) -> None: """Test hassio discovery flow is aborted for a non official add-on discovery.""" result2 = await hass.config_entries.flow.async_init( DOMAIN, @@ -605,6 +625,7 @@ async def test_abort_hassio_discovery_for_other_addon( assert result2["reason"] == "not_zwave_js_addon" +@pytest.mark.usefixtures("supervisor", "addon_not_installed", "addon_info") @pytest.mark.parametrize( ("usb_discovery_info", "device", "discovery_name"), [ @@ -627,26 +648,9 @@ async def test_abort_hassio_discovery_for_other_addon( ), ], ) -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) async def test_usb_discovery( hass: HomeAssistant, - supervisor, - addon_not_installed, install_addon, - addon_options, - get_addon_discovery_info, mock_usb_serial_by_id: MagicMock, set_addon_options, start_addon, @@ -751,28 +755,13 @@ async def test_usb_discovery( assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_installed") async def test_usb_discovery_addon_not_running( hass: HomeAssistant, - supervisor, - addon_installed, - addon_options, + addon_options: dict[str, Any], mock_usb_serial_by_id: MagicMock, - set_addon_options, - start_addon, - get_addon_discovery_info, + set_addon_options: AsyncMock, + start_addon: AsyncMock, ) -> None: """Test usb discovery when add-on is installed but not running.""" addon_options["device"] = "/dev/incorrect_device" @@ -872,20 +861,7 @@ async def test_usb_discovery_addon_not_running( assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.usefixtures("supervisor", "addon_running", "get_addon_discovery_info") -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running") async def test_usb_discovery_migration( hass: HomeAssistant, addon_options: dict[str, Any], @@ -1022,20 +998,7 @@ async def test_usb_discovery_migration( assert entry.unique_id == "5678" -@pytest.mark.usefixtures("supervisor", "addon_running", "get_addon_discovery_info") -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running") async def test_usb_discovery_migration_restore_driver_ready_timeout( hass: HomeAssistant, addon_options: dict[str, Any], @@ -1166,13 +1129,12 @@ async def test_usb_discovery_migration_restore_driver_ready_timeout( assert integration.data["use_addon"] is True +@pytest.mark.usefixtures("supervisor", "addon_installed") async def test_discovery_addon_not_running( hass: HomeAssistant, - supervisor, - addon_installed, - addon_options, - set_addon_options, - start_addon, + addon_options: dict[str, Any], + set_addon_options: AsyncMock, + start_addon: AsyncMock, ) -> None: """Test discovery with add-on already installed but not running.""" addon_options["device"] = None @@ -1260,14 +1222,12 @@ async def test_discovery_addon_not_running( assert len(mock_setup_entry.mock_calls) == 1 +@pytest.mark.usefixtures("supervisor", "addon_not_installed", "addon_info") async def test_discovery_addon_not_installed( hass: HomeAssistant, - supervisor, - addon_not_installed, - install_addon, - addon_options, - set_addon_options, - start_addon, + install_addon: AsyncMock, + set_addon_options: AsyncMock, + start_addon: AsyncMock, ) -> None: """Test discovery with add-on not installed.""" result = await hass.config_entries.flow.async_init( @@ -1362,9 +1322,8 @@ async def test_discovery_addon_not_installed( assert len(mock_setup_entry.mock_calls) == 1 -async def test_abort_usb_discovery_with_existing_flow( - hass: HomeAssistant, supervisor, addon_options -) -> None: +@pytest.mark.usefixtures("supervisor", "addon_info") +async def test_abort_usb_discovery_with_existing_flow(hass: HomeAssistant) -> None: """Test usb discovery flow is aborted when another discovery has happened.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -1429,9 +1388,8 @@ async def test_usb_discovery_with_existing_usb_flow(hass: HomeAssistant) -> None assert len(hass.config_entries.flow.async_progress()) == 0 -async def test_abort_usb_discovery_addon_required( - hass: HomeAssistant, supervisor, addon_options -) -> None: +@pytest.mark.usefixtures("supervisor", "addon_info") +async def test_abort_usb_discovery_addon_required(hass: HomeAssistant) -> None: """Test usb discovery aborted when existing entry not using add-on.""" entry = MockConfigEntry( domain=DOMAIN, @@ -1526,24 +1484,27 @@ async def test_usb_discovery_same_device( assert mock_usb_serial_by_id.call_count == 2 +@pytest.mark.usefixtures("supervisor", "addon_info") @pytest.mark.parametrize( - "discovery_info", + "usb_discovery_info", [CP2652_ZIGBEE_DISCOVERY_INFO], ) async def test_abort_usb_discovery_aborts_specific_devices( - hass: HomeAssistant, supervisor, addon_options, discovery_info + hass: HomeAssistant, + usb_discovery_info: UsbServiceInfo, ) -> None: """Test usb discovery flow is aborted on specific devices.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USB}, - data=discovery_info, + data=usb_discovery_info, ) assert result["type"] is FlowResultType.ABORT assert result["reason"] == "not_zwave_device" -async def test_not_addon(hass: HomeAssistant, supervisor) -> None: +@pytest.mark.usefixtures("supervisor") +async def test_not_addon(hass: HomeAssistant) -> None: """Test opting out of add-on on Supervisor.""" result = await hass.config_entries.flow.async_init( @@ -1602,25 +1563,10 @@ async def test_not_addon(hass: HomeAssistant, supervisor) -> None: assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running") async def test_addon_running( hass: HomeAssistant, - supervisor, - addon_running, addon_options, - get_addon_discovery_info, ) -> None: """Test add-on already running on Supervisor.""" addon_options["device"] = "/test" @@ -1677,6 +1623,7 @@ async def test_addon_running( assert len(mock_setup_entry.mock_calls) == 1 +@pytest.mark.usefixtures("supervisor", "addon_running") @pytest.mark.parametrize( ( "discovery_info", @@ -1739,11 +1686,8 @@ async def test_addon_running( ) async def test_addon_running_failures( hass: HomeAssistant, - supervisor, - addon_running, - addon_options, - get_addon_discovery_info, - abort_reason, + addon_options: dict[str, Any], + abort_reason: str, ) -> None: """Test all failures when add-on is running.""" addon_options["device"] = "/test" @@ -1771,25 +1715,10 @@ async def test_addon_running_failures( assert result["reason"] == abort_reason -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running") async def test_addon_running_already_configured( hass: HomeAssistant, - supervisor, - addon_running, - addon_options, - get_addon_discovery_info, + addon_options: dict[str, Any], ) -> None: """Test that only one unique instance is allowed when add-on is running.""" addon_options["device"] = "/test_new" @@ -1849,27 +1778,11 @@ async def test_addon_running_already_configured( assert entry.data["lr_s2_authenticated_key"] == "new321" -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_installed", "addon_info") async def test_addon_installed( hass: HomeAssistant, - supervisor, - addon_installed, - addon_options, - set_addon_options, - start_addon, - get_addon_discovery_info, + set_addon_options: AsyncMock, + start_addon: AsyncMock, ) -> None: """Test add-on already installed but not running on Supervisor.""" @@ -1958,28 +1871,12 @@ async def test_addon_installed( assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.parametrize( - ("discovery_info", "start_addon_side_effect"), - [ - ( - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ), - SupervisorError(), - ) - ], -) +@pytest.mark.usefixtures("supervisor", "addon_installed", "addon_info") +@pytest.mark.parametrize("start_addon_side_effect", [SupervisorError()]) async def test_addon_installed_start_failure( hass: HomeAssistant, - supervisor, - addon_installed, - addon_options, - set_addon_options, - start_addon, - get_addon_discovery_info, + set_addon_options: AsyncMock, + start_addon: AsyncMock, ) -> None: """Test add-on start failure when add-on is installed.""" @@ -2044,6 +1941,7 @@ async def test_addon_installed_start_failure( assert result["reason"] == "addon_start_failed" +@pytest.mark.usefixtures("supervisor", "addon_installed", "addon_info") @pytest.mark.parametrize( ("discovery_info", "server_version_side_effect"), [ @@ -2066,12 +1964,8 @@ async def test_addon_installed_start_failure( ) async def test_addon_installed_failures( hass: HomeAssistant, - supervisor, - addon_installed, - addon_options, - set_addon_options, - start_addon, - get_addon_discovery_info, + set_addon_options: AsyncMock, + start_addon: AsyncMock, ) -> None: """Test all failures when add-on is installed.""" @@ -2136,30 +2030,12 @@ async def test_addon_installed_failures( assert result["reason"] == "addon_start_failed" -@pytest.mark.parametrize( - ("set_addon_options_side_effect", "discovery_info"), - [ - ( - SupervisorError(), - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], - ) - ], -) +@pytest.mark.usefixtures("supervisor", "addon_installed", "addon_info") +@pytest.mark.parametrize("set_addon_options_side_effect", [SupervisorError()]) async def test_addon_installed_set_options_failure( hass: HomeAssistant, - supervisor, - addon_installed, - addon_options, - set_addon_options, - start_addon, - get_addon_discovery_info, + set_addon_options: AsyncMock, + start_addon: AsyncMock, ) -> None: """Test all failures when add-on is installed.""" @@ -2218,11 +2094,8 @@ async def test_addon_installed_set_options_failure( assert start_addon.call_count == 0 -async def test_addon_installed_usb_ports_failure( - hass: HomeAssistant, - supervisor, - addon_installed, -) -> None: +@pytest.mark.usefixtures("supervisor", "addon_installed") +async def test_addon_installed_usb_ports_failure(hass: HomeAssistant) -> None: """Test usb ports failure when add-on is installed.""" result = await hass.config_entries.flow.async_init( @@ -2251,27 +2124,11 @@ async def test_addon_installed_usb_ports_failure( assert result["reason"] == "usb_ports_failed" -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_installed", "addon_info") async def test_addon_installed_already_configured( hass: HomeAssistant, - supervisor, - addon_installed, - addon_options, - set_addon_options, - start_addon, - get_addon_discovery_info, + set_addon_options: AsyncMock, + start_addon: AsyncMock, ) -> None: """Test that only one unique instance is allowed when add-on is installed.""" entry = MockConfigEntry( @@ -2361,28 +2218,12 @@ async def test_addon_installed_already_configured( assert entry.data["lr_s2_authenticated_key"] == "new321" -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_not_installed", "addon_info") async def test_addon_not_installed( hass: HomeAssistant, - supervisor, - addon_not_installed, - install_addon, - addon_options, - set_addon_options, - start_addon, - get_addon_discovery_info, + install_addon: AsyncMock, + set_addon_options: AsyncMock, + start_addon: AsyncMock, ) -> None: """Test add-on not installed.""" result = await hass.config_entries.flow.async_init( @@ -2480,8 +2321,10 @@ async def test_addon_not_installed( assert len(mock_setup_entry.mock_calls) == 1 +@pytest.mark.usefixtures("supervisor", "addon_not_installed") async def test_install_addon_failure( - hass: HomeAssistant, supervisor, addon_not_installed, install_addon + hass: HomeAssistant, + install_addon: AsyncMock, ) -> None: """Test add-on install failure.""" install_addon.side_effect = SupervisorError() @@ -2517,7 +2360,11 @@ async def test_install_addon_failure( assert result["reason"] == "addon_install_failed" -async def test_reconfigure_manual(hass: HomeAssistant, client, integration) -> None: +async def test_reconfigure_manual( + hass: HomeAssistant, + client: MagicMock, + integration: MockConfigEntry, +) -> None: """Test manual settings in reconfigure flow.""" entry = integration hass.config_entries.async_update_entry(entry, unique_id="1234") @@ -2552,7 +2399,8 @@ async def test_reconfigure_manual(hass: HomeAssistant, client, integration) -> N async def test_reconfigure_manual_different_device( - hass: HomeAssistant, integration + hass: HomeAssistant, + integration: MockConfigEntry, ) -> None: """Test reconfigure flow manual step connecting to different device.""" entry = integration @@ -2579,8 +2427,11 @@ async def test_reconfigure_manual_different_device( assert result["reason"] == "different_device" +@pytest.mark.usefixtures("supervisor") async def test_reconfigure_not_addon( - hass: HomeAssistant, client, supervisor, integration + hass: HomeAssistant, + client: MagicMock, + integration: MockConfigEntry, ) -> None: """Test reconfigure flow and opting out of add-on on Supervisor.""" entry = integration @@ -2745,9 +2596,9 @@ async def test_reconfigure_not_addon_with_addon_stop_fail( assert entry.state is config_entries.ConfigEntryState.NOT_LOADED +@pytest.mark.usefixtures("supervisor", "addon_running") @pytest.mark.parametrize( ( - "discovery_info", "entry_data", "old_addon_options", "new_addon_options", @@ -2755,14 +2606,6 @@ async def test_reconfigure_not_addon_with_addon_stop_fail( ), [ ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], {}, { "device": "/test", @@ -2788,14 +2631,6 @@ async def test_reconfigure_not_addon_with_addon_stop_fail( 0, ), ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], {"use_addon": True}, { "device": "/test", @@ -2825,14 +2660,10 @@ async def test_reconfigure_not_addon_with_addon_stop_fail( async def test_reconfigure_addon_running( hass: HomeAssistant, client, - supervisor, integration, - addon_running, addon_options, set_addon_options, restart_addon, - get_addon_discovery_info, - discovery_info, entry_data, old_addon_options, new_addon_options, @@ -2919,18 +2750,11 @@ async def test_reconfigure_addon_running( assert client.disconnect.call_count == 1 +@pytest.mark.usefixtures("supervisor", "addon_running") @pytest.mark.parametrize( - ("discovery_info", "entry_data", "old_addon_options", "new_addon_options"), + ("entry_data", "old_addon_options", "new_addon_options"), [ ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], {}, { "device": "/test", @@ -2961,14 +2785,10 @@ async def test_reconfigure_addon_running( async def test_reconfigure_addon_running_no_changes( hass: HomeAssistant, client, - supervisor, integration, - addon_running, addon_options, set_addon_options, restart_addon, - get_addon_discovery_info, - discovery_info, entry_data, old_addon_options, new_addon_options, @@ -3054,9 +2874,9 @@ async def different_device_server_version(*args): ) +@pytest.mark.usefixtures("supervisor", "addon_running") @pytest.mark.parametrize( ( - "discovery_info", "entry_data", "old_addon_options", "new_addon_options", @@ -3065,14 +2885,6 @@ async def different_device_server_version(*args): ), [ ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], {}, { "device": "/test", @@ -3101,14 +2913,6 @@ async def different_device_server_version(*args): different_device_server_version, ), ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], {}, { "device": "/test", @@ -3140,19 +2944,14 @@ async def different_device_server_version(*args): async def test_reconfigure_different_device( hass: HomeAssistant, client, - supervisor, integration, - addon_running, addon_options, set_addon_options, restart_addon, - get_addon_discovery_info, - discovery_info, entry_data, old_addon_options, new_addon_options, disconnect_calls, - server_version_side_effect, ) -> None: """Test reconfigure flow and configuring a different device.""" addon_options.update(old_addon_options) @@ -3233,9 +3032,9 @@ async def test_reconfigure_different_device( assert client.disconnect.call_count == 1 +@pytest.mark.usefixtures("supervisor", "addon_running") @pytest.mark.parametrize( ( - "discovery_info", "entry_data", "old_addon_options", "new_addon_options", @@ -3244,14 +3043,6 @@ async def test_reconfigure_different_device( ), [ ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], {}, { "device": "/test", @@ -3280,14 +3071,6 @@ async def test_reconfigure_different_device( [SupervisorError(), None], ), ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], {}, { "device": "/test", @@ -3323,19 +3106,14 @@ async def test_reconfigure_different_device( async def test_reconfigure_addon_restart_failed( hass: HomeAssistant, client, - supervisor, integration, - addon_running, addon_options, set_addon_options, restart_addon, - get_addon_discovery_info, - discovery_info, entry_data, old_addon_options, new_addon_options, disconnect_calls, - restart_addon_side_effect, ) -> None: """Test reconfigure flow and add-on restart failure.""" addon_options.update(old_addon_options) @@ -3413,76 +3191,42 @@ async def test_reconfigure_addon_restart_failed( assert client.disconnect.call_count == 1 -@pytest.mark.parametrize( - ( - "discovery_info", - "entry_data", - "old_addon_options", - "new_addon_options", - "disconnect_calls", - "server_version_side_effect", - ), - [ - ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], - {}, - { - "device": "/test", - "network_key": "abc123", - "s0_legacy_key": "abc123", - "s2_access_control_key": "old456", - "s2_authenticated_key": "old789", - "s2_unauthenticated_key": "old987", - "lr_s2_access_control_key": "old654", - "lr_s2_authenticated_key": "old321", - "log_level": "info", - "emulate_hardware": False, - }, - { - "usb_path": "/test", - "s0_legacy_key": "abc123", - "s2_access_control_key": "old456", - "s2_authenticated_key": "old789", - "s2_unauthenticated_key": "old987", - "lr_s2_access_control_key": "old654", - "lr_s2_authenticated_key": "old321", - "log_level": "info", - "emulate_hardware": False, - }, - 0, - aiohttp.ClientError("Boom"), - ), - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running", "restart_addon") +@pytest.mark.parametrize("server_version_side_effect", [aiohttp.ClientError("Boom")]) async def test_reconfigure_addon_running_server_info_failure( hass: HomeAssistant, - client, - supervisor, - integration, - addon_running, - addon_options, - set_addon_options, - restart_addon, - get_addon_discovery_info, - discovery_info, - entry_data, - old_addon_options, - new_addon_options, - disconnect_calls, - server_version_side_effect, + client: MagicMock, + integration: MockConfigEntry, + addon_options: dict[str, Any], + set_addon_options: AsyncMock, ) -> None: """Test reconfigure flow and add-on already running with server info failure.""" + old_addon_options = { + "device": "/test", + "network_key": "abc123", + "s0_legacy_key": "abc123", + "s2_access_control_key": "old456", + "s2_authenticated_key": "old789", + "s2_unauthenticated_key": "old987", + "lr_s2_access_control_key": "old654", + "lr_s2_authenticated_key": "old321", + "log_level": "info", + "emulate_hardware": False, + } + new_addon_options = { + "usb_path": "/test", + "s0_legacy_key": "abc123", + "s2_access_control_key": "old456", + "s2_authenticated_key": "old789", + "s2_unauthenticated_key": "old987", + "lr_s2_access_control_key": "old654", + "lr_s2_authenticated_key": "old321", + "log_level": "info", + "emulate_hardware": False, + } addon_options.update(old_addon_options) entry = integration - data = {**entry.data, **entry_data} - hass.config_entries.async_update_entry(entry, data=data, unique_id="1234") + hass.config_entries.async_update_entry(entry, unique_id="1234") assert entry.data["url"] == "ws://test.org" @@ -3516,14 +3260,15 @@ async def test_reconfigure_addon_running_server_info_failure( assert result["type"] is FlowResultType.ABORT assert result["reason"] == "cannot_connect" - assert entry.data == data + assert entry.data["url"] == "ws://test.org" + assert set_addon_options.call_count == 0 assert client.connect.call_count == 2 assert client.disconnect.call_count == 1 +@pytest.mark.usefixtures("supervisor", "addon_not_installed") @pytest.mark.parametrize( ( - "discovery_info", "entry_data", "old_addon_options", "new_addon_options", @@ -3531,14 +3276,6 @@ async def test_reconfigure_addon_running_server_info_failure( ), [ ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], {}, { "device": "/test", @@ -3564,14 +3301,6 @@ async def test_reconfigure_addon_running_server_info_failure( 0, ), ( - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ], {"use_addon": True}, { "device": "/test", @@ -3601,15 +3330,11 @@ async def test_reconfigure_addon_running_server_info_failure( async def test_reconfigure_addon_not_installed( hass: HomeAssistant, client, - supervisor, - addon_not_installed, install_addon, integration, addon_options, set_addon_options, start_addon, - get_addon_discovery_info, - discovery_info, entry_data, old_addon_options, new_addon_options, @@ -3783,19 +3508,7 @@ async def test_reconfigure_migrate_low_sdk_version( assert result["reason"] == "migration_low_sdk_version" -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running") @pytest.mark.parametrize( ( "reset_server_version_side_effect", @@ -3813,13 +3526,10 @@ async def test_reconfigure_migrate_low_sdk_version( async def test_reconfigure_migrate_with_addon( hass: HomeAssistant, client, - supervisor, integration, - addon_running, restart_addon, addon_options, set_addon_options, - get_addon_discovery_info, get_server_version: AsyncMock, reset_server_version_side_effect: Exception | None, reset_unique_id: str, @@ -3971,28 +3681,13 @@ async def test_reconfigure_migrate_with_addon( assert entry.unique_id == final_unique_id -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running") async def test_reconfigure_migrate_reset_driver_ready_timeout( hass: HomeAssistant, client, - supervisor, integration, - addon_running, restart_addon, set_addon_options, - get_addon_discovery_info, get_server_version: AsyncMock, ) -> None: """Test migration flow with driver ready timeout after controller reset.""" @@ -4133,28 +3828,13 @@ async def test_reconfigure_migrate_reset_driver_ready_timeout( assert entry.unique_id == "5678" -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running") async def test_reconfigure_migrate_restore_driver_ready_timeout( hass: HomeAssistant, client, - supervisor, integration, - addon_running, restart_addon, set_addon_options, - get_addon_discovery_info, ) -> None: """Test migration flow with driver ready timeout after nvm restore.""" entry = integration @@ -4286,7 +3966,9 @@ async def test_reconfigure_migrate_restore_driver_ready_timeout( async def test_reconfigure_migrate_backup_failure( - hass: HomeAssistant, integration, client + hass: HomeAssistant, + integration: MockConfigEntry, + client: MagicMock, ) -> None: """Test backup failure.""" entry = integration @@ -4317,7 +3999,9 @@ async def test_reconfigure_migrate_backup_failure( async def test_reconfigure_migrate_backup_file_failure( - hass: HomeAssistant, integration, client + hass: HomeAssistant, + integration: MockConfigEntry, + client: MagicMock, ) -> None: """Test backup file failure.""" entry = integration @@ -4360,20 +4044,7 @@ async def test_reconfigure_migrate_backup_file_failure( assert result["reason"] == "backup_failed" -@pytest.mark.usefixtures("supervisor", "addon_running", "get_addon_discovery_info") -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running") async def test_reconfigure_migrate_start_addon_failure( hass: HomeAssistant, client: MagicMock, @@ -4458,28 +4129,12 @@ async def test_reconfigure_migrate_start_addon_failure( assert result["reason"] == "addon_start_failed" -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_running", "restart_addon") async def test_reconfigure_migrate_restore_failure( hass: HomeAssistant, - client, - supervisor, - integration, - addon_running, - restart_addon, - set_addon_options, - get_addon_discovery_info, + client: MagicMock, + integration: MockConfigEntry, + set_addon_options: AsyncMock, ) -> None: """Test restore failure.""" entry = integration @@ -4545,6 +4200,7 @@ async def test_reconfigure_migrate_restore_failure( }, ) + assert set_addon_options.call_count == 1 assert result["type"] is FlowResultType.SHOW_PROGRESS assert result["step_id"] == "start_addon" @@ -4656,7 +4312,11 @@ async def test_get_driver_failure_instruct_unplug( assert result["reason"] == "config_entry_not_loaded" -async def test_hard_reset_failure(hass: HomeAssistant, integration, client) -> None: +async def test_hard_reset_failure( + hass: HomeAssistant, + integration: MockConfigEntry, + client: MagicMock, +) -> None: """Test hard reset failure.""" entry = integration hass.config_entries.async_update_entry( @@ -4703,7 +4363,9 @@ async def test_hard_reset_failure(hass: HomeAssistant, integration, client) -> N async def test_choose_serial_port_usb_ports_failure( - hass: HomeAssistant, integration, client + hass: HomeAssistant, + integration: MockConfigEntry, + client: MagicMock, ) -> None: """Test choose serial port usb ports failure.""" entry = integration @@ -4763,8 +4425,10 @@ async def test_choose_serial_port_usb_ports_failure( assert result["reason"] == "usb_ports_failed" +@pytest.mark.usefixtures("supervisor", "addon_installed") async def test_configure_addon_usb_ports_failure( - hass: HomeAssistant, integration, addon_installed, supervisor + hass: HomeAssistant, + integration: MockConfigEntry, ) -> None: """Test configure addon usb ports failure.""" entry = integration @@ -4791,7 +4455,7 @@ async def test_configure_addon_usb_ports_failure( assert result["reason"] == "usb_ports_failed" -async def test_get_usb_ports_sorting(hass: HomeAssistant) -> None: +async def test_get_usb_ports_sorting() -> None: """Test that get_usb_ports sorts ports with 'n/a' descriptions last.""" mock_ports = [ ListPortInfo("/dev/ttyUSB0"), @@ -4819,28 +4483,12 @@ async def test_get_usb_ports_sorting(hass: HomeAssistant) -> None: ] -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) +@pytest.mark.usefixtures("supervisor", "addon_not_installed", "addon_info") async def test_intent_recommended_user( hass: HomeAssistant, - supervisor, - addon_not_installed, - install_addon, - start_addon, - addon_options, - set_addon_options, - get_addon_discovery_info, + install_addon: AsyncMock, + start_addon: AsyncMock, + set_addon_options: AsyncMock, ) -> None: """Test the intent_recommended step.""" result = await hass.config_entries.flow.async_init( @@ -4932,6 +4580,7 @@ async def test_intent_recommended_user( assert len(mock_setup_entry.mock_calls) == 1 +@pytest.mark.usefixtures("supervisor", "addon_not_installed", "addon_info") @pytest.mark.parametrize( ("usb_discovery_info", "device", "discovery_name"), [ @@ -4954,29 +4603,12 @@ async def test_intent_recommended_user( ), ], ) -@pytest.mark.parametrize( - "discovery_info", - [ - [ - Discovery( - addon="core_zwave_js", - service="zwave_js", - uuid=uuid4(), - config=ADDON_DISCOVERY_INFO, - ) - ] - ], -) async def test_recommended_usb_discovery( hass: HomeAssistant, - supervisor, - addon_not_installed, - install_addon, - addon_options, - get_addon_discovery_info, + install_addon: AsyncMock, mock_usb_serial_by_id: MagicMock, - set_addon_options, - start_addon, + set_addon_options: AsyncMock, + start_addon: AsyncMock, usb_discovery_info: UsbServiceInfo, device: str, discovery_name: str,