core icon indicating copy to clipboard operation
core copied to clipboard

Add a helper to create config flow `step_id` names from functions

Open puddly opened this issue 7 months ago • 1 comments

Proposed change

During development, I've run into a few situations where the config flow step ID string does not refer to a real step. This is only caught at runtime, as opposed to by the type checker.

This PR introduces FlowHandler.get_step_id to derive the step_id directly from a reference to the function:

 return self.async_show_form(
-    step_id="first",
+    step_id=self.get_step_id(self.async_step_first),
     data_schema=vol.Schema([str]),
 )

Any mistakes are caught by mypy directly:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

homeassistant/components/zha/config_flow.py:779: error: "ZhaOptionsFlowHandler" has no attribute "async_step_intent_migrates"; maybe "async_step_intent_migrate" or "async_step_intent_reconfigure"?  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

An alternative implementation would be to add a step= kwarg to all of the FlowHandler functions and pass the step function in directly.

Type of change

  • [ ] Dependency upgrade
  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [ ] New integration (thank you!)
  • [ ] New feature (which adds functionality to an existing integration)
  • [ ] Deprecation (breaking change to happen in the future)
  • [ ] Breaking change (fix/feature causing existing functionality to break)
  • [x] Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • [x] The code change is tested and works locally.
  • [x] Local tests pass. Your PR cannot be merged unless tests pass
  • [x] There is no commented out code in this PR.
  • [x] I have followed the development checklist
  • [x] I have followed the perfect PR recommendations
  • [x] The code has been formatted using Ruff (ruff format homeassistant tests)
  • [x] Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • [ ] The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • [ ] New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

puddly avatar May 12 '25 18:05 puddly

CI failure is in Roku and unrelated to this PR.

puddly avatar May 12 '25 19:05 puddly

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes. Thank you for your contribution!

github-actions[bot] avatar Jul 11 '25 20:07 github-actions[bot]