Improve Z-Wave config flow test typing (#145438)

This commit is contained in:
Martin Hjelmare 2025-05-22 11:11:38 +02:00 committed by GitHub
parent b5a3cedacd
commit c007286fd6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -246,7 +246,7 @@ async def test_manual(hass: HomeAssistant) -> None:
assert result2["result"].unique_id == "1234" assert result2["result"].unique_id == "1234"
async def slow_server_version(*args): async def slow_server_version(*args: Any) -> Any:
"""Simulate a slow server version.""" """Simulate a slow server version."""
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
@ -650,10 +650,10 @@ async def test_abort_hassio_discovery_for_other_addon(hass: HomeAssistant) -> No
) )
async def test_usb_discovery( async def test_usb_discovery(
hass: HomeAssistant, hass: HomeAssistant,
install_addon, install_addon: AsyncMock,
mock_usb_serial_by_id: MagicMock, mock_usb_serial_by_id: MagicMock,
set_addon_options, set_addon_options: AsyncMock,
start_addon, start_addon: AsyncMock,
usb_discovery_info: UsbServiceInfo, usb_discovery_info: UsbServiceInfo,
device: str, device: str,
discovery_name: str, discovery_name: str,
@ -789,6 +789,7 @@ async def test_usb_discovery_addon_not_running(
# Make sure the discovered usb device is preferred. # Make sure the discovered usb device is preferred.
data_schema = result["data_schema"] data_schema = result["data_schema"]
assert data_schema is not None
assert data_schema({}) == { assert data_schema({}) == {
"s0_legacy_key": "", "s0_legacy_key": "",
"s2_access_control_key": "", "s2_access_control_key": "",
@ -1566,7 +1567,7 @@ async def test_not_addon(hass: HomeAssistant) -> None:
@pytest.mark.usefixtures("supervisor", "addon_running") @pytest.mark.usefixtures("supervisor", "addon_running")
async def test_addon_running( async def test_addon_running(
hass: HomeAssistant, hass: HomeAssistant,
addon_options, addon_options: dict[str, Any],
) -> None: ) -> None:
"""Test add-on already running on Supervisor.""" """Test add-on already running on Supervisor."""
addon_options["device"] = "/test" addon_options["device"] = "/test"
@ -2659,15 +2660,15 @@ async def test_reconfigure_not_addon_with_addon_stop_fail(
) )
async def test_reconfigure_addon_running( async def test_reconfigure_addon_running(
hass: HomeAssistant, hass: HomeAssistant,
client, client: MagicMock,
integration, integration: MockConfigEntry,
addon_options, addon_options: dict[str, Any],
set_addon_options, set_addon_options: AsyncMock,
restart_addon, restart_addon: AsyncMock,
entry_data, entry_data: dict[str, Any],
old_addon_options, old_addon_options: dict[str, Any],
new_addon_options, new_addon_options: dict[str, Any],
disconnect_calls, disconnect_calls: int,
) -> None: ) -> None:
"""Test reconfigure flow and add-on already running on Supervisor.""" """Test reconfigure flow and add-on already running on Supervisor."""
addon_options.update(old_addon_options) addon_options.update(old_addon_options)
@ -2784,14 +2785,14 @@ async def test_reconfigure_addon_running(
) )
async def test_reconfigure_addon_running_no_changes( async def test_reconfigure_addon_running_no_changes(
hass: HomeAssistant, hass: HomeAssistant,
client, client: MagicMock,
integration, integration: MockConfigEntry,
addon_options, addon_options: dict[str, Any],
set_addon_options, set_addon_options: AsyncMock,
restart_addon, restart_addon: AsyncMock,
entry_data, entry_data: dict[str, Any],
old_addon_options, old_addon_options: dict[str, Any],
new_addon_options, new_addon_options: dict[str, Any],
) -> None: ) -> None:
"""Test reconfigure flow without changes, and add-on already running on Supervisor.""" """Test reconfigure flow without changes, and add-on already running on Supervisor."""
addon_options.update(old_addon_options) addon_options.update(old_addon_options)
@ -2943,15 +2944,15 @@ async def different_device_server_version(*args):
) )
async def test_reconfigure_different_device( async def test_reconfigure_different_device(
hass: HomeAssistant, hass: HomeAssistant,
client, client: MagicMock,
integration, integration: MockConfigEntry,
addon_options, addon_options: dict[str, Any],
set_addon_options, set_addon_options: AsyncMock,
restart_addon, restart_addon: AsyncMock,
entry_data, entry_data: dict[str, Any],
old_addon_options, old_addon_options: dict[str, Any],
new_addon_options, new_addon_options: dict[str, Any],
disconnect_calls, disconnect_calls: int,
) -> None: ) -> None:
"""Test reconfigure flow and configuring a different device.""" """Test reconfigure flow and configuring a different device."""
addon_options.update(old_addon_options) addon_options.update(old_addon_options)
@ -3105,15 +3106,15 @@ async def test_reconfigure_different_device(
) )
async def test_reconfigure_addon_restart_failed( async def test_reconfigure_addon_restart_failed(
hass: HomeAssistant, hass: HomeAssistant,
client, client: MagicMock,
integration, integration: MockConfigEntry,
addon_options, addon_options: dict[str, Any],
set_addon_options, set_addon_options: AsyncMock,
restart_addon, restart_addon: AsyncMock,
entry_data, entry_data: dict[str, Any],
old_addon_options, old_addon_options: dict[str, Any],
new_addon_options, new_addon_options: dict[str, Any],
disconnect_calls, disconnect_calls: int,
) -> None: ) -> None:
"""Test reconfigure flow and add-on restart failure.""" """Test reconfigure flow and add-on restart failure."""
addon_options.update(old_addon_options) addon_options.update(old_addon_options)
@ -3329,16 +3330,16 @@ async def test_reconfigure_addon_running_server_info_failure(
) )
async def test_reconfigure_addon_not_installed( async def test_reconfigure_addon_not_installed(
hass: HomeAssistant, hass: HomeAssistant,
client, client: MagicMock,
install_addon, install_addon: AsyncMock,
integration, integration: MockConfigEntry,
addon_options, addon_options: dict[str, Any],
set_addon_options, set_addon_options: AsyncMock,
start_addon, start_addon: AsyncMock,
entry_data, entry_data: dict[str, Any],
old_addon_options, old_addon_options: dict[str, Any],
new_addon_options, new_addon_options: dict[str, Any],
disconnect_calls, disconnect_calls: int,
) -> None: ) -> None:
"""Test reconfigure flow and add-on not installed on Supervisor.""" """Test reconfigure flow and add-on not installed on Supervisor."""
addon_options.update(old_addon_options) addon_options.update(old_addon_options)
@ -3464,7 +3465,10 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_reconfigure_migrate_no_addon(hass: HomeAssistant, integration) -> None: async def test_reconfigure_migrate_no_addon(
hass: HomeAssistant,
integration: MockConfigEntry,
) -> None:
"""Test migration flow fails when not using add-on.""" """Test migration flow fails when not using add-on."""
entry = integration entry = integration
hass.config_entries.async_update_entry( hass.config_entries.async_update_entry(
@ -3525,11 +3529,11 @@ async def test_reconfigure_migrate_low_sdk_version(
) )
async def test_reconfigure_migrate_with_addon( async def test_reconfigure_migrate_with_addon(
hass: HomeAssistant, hass: HomeAssistant,
client, client: MagicMock,
integration, integration: MockConfigEntry,
restart_addon, restart_addon: AsyncMock,
addon_options, addon_options: dict[str, Any],
set_addon_options, set_addon_options: AsyncMock,
get_server_version: AsyncMock, get_server_version: AsyncMock,
reset_server_version_side_effect: Exception | None, reset_server_version_side_effect: Exception | None,
reset_unique_id: str, reset_unique_id: str,
@ -3627,10 +3631,12 @@ async def test_reconfigure_migrate_with_addon(
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "choose_serial_port" assert result["step_id"] == "choose_serial_port"
assert result["data_schema"].schema[CONF_USB_PATH] data_schema = result["data_schema"]
assert data_schema is not None
assert data_schema.schema[CONF_USB_PATH]
# Ensure the old usb path is not in the list of options # Ensure the old usb path is not in the list of options
with pytest.raises(InInvalid): with pytest.raises(InInvalid):
result["data_schema"].schema[CONF_USB_PATH](addon_options["device"]) data_schema.schema[CONF_USB_PATH](addon_options["device"])
# Reset side effect before starting the add-on. # Reset side effect before starting the add-on.
get_server_version.side_effect = None get_server_version.side_effect = None
@ -3684,10 +3690,10 @@ async def test_reconfigure_migrate_with_addon(
@pytest.mark.usefixtures("supervisor", "addon_running") @pytest.mark.usefixtures("supervisor", "addon_running")
async def test_reconfigure_migrate_reset_driver_ready_timeout( async def test_reconfigure_migrate_reset_driver_ready_timeout(
hass: HomeAssistant, hass: HomeAssistant,
client, client: MagicMock,
integration, integration: MockConfigEntry,
restart_addon, restart_addon: AsyncMock,
set_addon_options, set_addon_options: AsyncMock,
get_server_version: AsyncMock, get_server_version: AsyncMock,
) -> None: ) -> None:
"""Test migration flow with driver ready timeout after controller reset.""" """Test migration flow with driver ready timeout after controller reset."""
@ -3783,7 +3789,9 @@ async def test_reconfigure_migrate_reset_driver_ready_timeout(
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "choose_serial_port" assert result["step_id"] == "choose_serial_port"
assert result["data_schema"].schema[CONF_USB_PATH] data_schema = result["data_schema"]
assert data_schema is not None
assert data_schema.schema[CONF_USB_PATH]
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -3831,10 +3839,10 @@ async def test_reconfigure_migrate_reset_driver_ready_timeout(
@pytest.mark.usefixtures("supervisor", "addon_running") @pytest.mark.usefixtures("supervisor", "addon_running")
async def test_reconfigure_migrate_restore_driver_ready_timeout( async def test_reconfigure_migrate_restore_driver_ready_timeout(
hass: HomeAssistant, hass: HomeAssistant,
client, client: MagicMock,
integration, integration: MockConfigEntry,
restart_addon, restart_addon: AsyncMock,
set_addon_options, set_addon_options: AsyncMock,
) -> None: ) -> None:
"""Test migration flow with driver ready timeout after nvm restore.""" """Test migration flow with driver ready timeout after nvm restore."""
entry = integration entry = integration
@ -3919,7 +3927,9 @@ async def test_reconfigure_migrate_restore_driver_ready_timeout(
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "choose_serial_port" assert result["step_id"] == "choose_serial_port"
assert result["data_schema"].schema[CONF_USB_PATH] data_schema = result["data_schema"]
assert data_schema is not None
assert data_schema.schema[CONF_USB_PATH]
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -4218,7 +4228,9 @@ async def test_reconfigure_migrate_restore_failure(
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "restore_failed" assert result["step_id"] == "restore_failed"
assert result["description_placeholders"]["file_path"] description_placeholders = result["description_placeholders"]
assert description_placeholders is not None
assert description_placeholders["file_path"]
result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
@ -4514,13 +4526,15 @@ async def test_intent_recommended_user(
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "configure_addon_user" assert result["step_id"] == "configure_addon_user"
assert result["data_schema"].schema[CONF_USB_PATH] is not None data_schema = result["data_schema"]
assert result["data_schema"].schema.get(CONF_S0_LEGACY_KEY) is None assert data_schema is not None
assert result["data_schema"].schema.get(CONF_S2_ACCESS_CONTROL_KEY) is None assert data_schema.schema[CONF_USB_PATH] is not None
assert result["data_schema"].schema.get(CONF_S2_AUTHENTICATED_KEY) is None assert data_schema.schema.get(CONF_S0_LEGACY_KEY) is None
assert result["data_schema"].schema.get(CONF_S2_UNAUTHENTICATED_KEY) is None assert data_schema.schema.get(CONF_S2_ACCESS_CONTROL_KEY) is None
assert result["data_schema"].schema.get(CONF_LR_S2_ACCESS_CONTROL_KEY) is None assert data_schema.schema.get(CONF_S2_AUTHENTICATED_KEY) is None
assert result["data_schema"].schema.get(CONF_LR_S2_AUTHENTICATED_KEY) is None assert data_schema.schema.get(CONF_S2_UNAUTHENTICATED_KEY) is None
assert data_schema.schema.get(CONF_LR_S2_ACCESS_CONTROL_KEY) is None
assert data_schema.schema.get(CONF_LR_S2_AUTHENTICATED_KEY) is None
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],