Skip to content

Help confusion with subentries #2708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

HarvsG
Copy link

@HarvsG HarvsG commented Jun 19, 2025

Proposed change

Not all config entries use the async_step_{step_id} format and so we can't assume all devs will be familiar with it.
This documents many of the features that eluded me, and confused me.
Others on the discord also seem to find the docs difficult

Type of change

  • Document existing features within Home Assistant
  • Document new or changing features for which there is an existing pull request elsewhere
  • Spelling or grammatical corrections, or rewording for improved clarity
  • Changes to the backend of this documentation
  • Remove stale or deprecated documentation

Checklist

  • I have read and followed the documentation guidelines.
  • I have verified that my changes render correctly in the documentation.

Additional information

  • This PR fixes or closes issue: fixes #
  • Link to relevant existing code or pull request:

Summary by CodeRabbit

  • Documentation
    • Expanded documentation to describe the full implementation of user and reconfiguration steps in the configuration flow, including input validation, error handling, and form display with suggested values and contextual descriptions.

Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

Warning

Rate limit exceeded

@HarvsG has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b4b935b and 14795c6.

📒 Files selected for processing (1)
  • docs/config_entries_config_flow_handler.md (3 hunks)
📝 Walkthrough

Walkthrough

The LocationSubentryFlowHandler class in the documentation was updated to provide full implementations for the async_step_user and async_step_reconfigure methods. These methods now handle user input, perform validation, manage errors, and display forms with suggested values and contextual descriptions for subentry configuration flows.

Changes

File Change Summary
docs/config_entries_config_flow_handler.md Implemented async_step_user and async_step_reconfigure methods in LocationSubentryFlowHandler to handle user input, validation, error reporting, and form display for subentry configuration and reconfiguration flows.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FlowHandler as LocationSubentryFlowHandler
    participant Validator
    participant ConfigManager

    User->>FlowHandler: async_step_user(user_input)
    alt user_input is None
        FlowHandler->>User: Show form (initial)
    else user_input provided
        FlowHandler->>Validator: _validate_subentry(user_input)
        alt validation success
            FlowHandler->>ConfigManager: create subentry config entry
            FlowHandler->>User: Complete flow
        else validation error
            FlowHandler->>User: Show form with errors
        end
    end
Loading
sequenceDiagram
    participant User
    participant FlowHandler as LocationSubentryFlowHandler
    participant ConfigManager
    participant Validator

    User->>FlowHandler: async_step_reconfigure(user_input)
    FlowHandler->>ConfigManager: get parent config entry and subentry

    alt user_input is None
        FlowHandler->>User: Show form (prefilled)
    else user_input provided
        FlowHandler->>Validator: validate user_input (with duplicate check)
        alt validation success
            FlowHandler->>ConfigManager: update subentry
            FlowHandler->>User: Abort flow (success)
        else validation error
            FlowHandler->>User: Show form with errors
        end
    end
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/config_entries_config_flow_handler.md (1)

437-471: Fix typo and improve docstring punctuation.

There's a misspelling in the docstring (FnctionFunction) and the format string and sentences should end with periods.
Apply this diff:

@@ async_step_user(self, user_input: dict[str, Any] | None = None) -> SubentryFlowResult:
-        """User flow to add a new location.
-
-        Fnction name must be in the format "async_step_{step_id}"
-        The first step is always "user"
-        """
+        """User flow to add a new location.
+
+        Function name must be in the format async_step_{step_id}.
+        The first step is always user.
+        """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between a5c8faa and 4b327be.

📒 Files selected for processing (1)
  • docs/config_entries_config_flow_handler.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`*/**(html|markdown|md)`: - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure t...

*/**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'
  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: - Use bold to mark UI strings. - If "" are used to mark UI strings, replace them by bold.

*/**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.
  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

*/**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: - Use sentence-style capitalization also in headings.

*/**(html|markdown|md): - Use sentence-style capitalization also in headings.

  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: do not comment on HTML used for icons

*/**(html|markdown|md): do not comment on HTML used for icons

  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: Avoid flagging inline HTML for embedding videos in future reviews for this repository.

*/**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

  • docs/config_entries_config_flow_handler.md
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - developers-home-assistant
  • GitHub Check: Header rules - developers-home-assistant
  • GitHub Check: Pages changed - developers-home-assistant

Comment on lines 529 to 561

if user_input is not None:
# validate user_input, possibly with some checks on ther subentries
# If checking for duplicates remeber to remove the entry you are reconfiguring
other_subentries = [
dict(se.data) for se in self._get_entry().subentries.values()
]
other_subentries.remove(dict(config_subentry.data))
try:
... #validation
return self.async_update_and_abort(
self._get_entry(),
config_subentry,
title=user_input.get(CONF_NAME, config_subentry.data[CONF_NAME]),
data_updates=user_input,
)
except (SchemaFlowError) as err:
_LOGGER.error("Error reconfiguring subentry: %s", err)
# errors can be attached the base of a form or to a specific field
errors["base"] = str(err)

return self.async_show_form(
step_id="reconfigure",
# You will likely want to fetch original values
data_schema=self.add_suggested_values_to_schema(
data_schema=SUBENTRY_SCHEMA,
suggested_values=config_subentry.data,
),
errors=errors,
description_placeholders={
"parent_entry_title": self._get_entry().title,
},
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Initialize errors in async_step_reconfigure to avoid NameError.

The snippet references errors["base"] without defining errors, causing an exception. Also ensure SchemaFlowError is imported.
Apply this diff:

@@ async_step_reconfigure(self, user_input: dict[str, Any] | None = None) -> SubentryFlowResult:
-        config_subentry = self._get_reconfigure_subentry()
+        config_subentry = self._get_reconfigure_subentry()
+        errors: dict[str, str] = {}

         if user_input is not None:
             # validate user_input...

Optionally, at the top of the example add:

from homeassistant.data_entry_flow import SchemaFlowError
🤖 Prompt for AI Agents
In docs/config_entries_config_flow_handler.md around lines 529 to 561, the
variable errors is used without initialization, causing a NameError. Initialize
errors as an empty dictionary at the start of the async_step_reconfigure method
before it is used. Also, ensure that SchemaFlowError is imported from
homeassistant.data_entry_flow at the top of the file to avoid import errors.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
docs/config_entries_config_flow_handler.md (1)

454-454: Import SchemaFlowError to avoid NameError
The except clause references SchemaFlowError without importing it. Add at the top of the snippet:

+from homeassistant.data_entry_flow import SchemaFlowError
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 36c2e43 and b4b935b.

📒 Files selected for processing (1)
  • docs/config_entries_config_flow_handler.md (3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`*/**(html|markdown|md)`: - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure t...

*/**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'
  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: - Use bold to mark UI strings. - If "" are used to mark UI strings, replace them by bold.

*/**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.
  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

*/**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: - Use sentence-style capitalization also in headings.

*/**(html|markdown|md): - Use sentence-style capitalization also in headings.

  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: do not comment on HTML used for icons

*/**(html|markdown|md): do not comment on HTML used for icons

  • docs/config_entries_config_flow_handler.md
`*/**(html|markdown|md)`: Avoid flagging inline HTML for embedding videos in future reviews for this repository.

*/**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

  • docs/config_entries_config_flow_handler.md

Comment on lines +449 to +450
user_input = await _validate_subentry(user_input)
return self.async_create_entry(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Qualify call to _validate_subentry
The call to _validate_subentry lacks a qualifier and will raise a NameError. Either prefix it with self. (await self._validate_subentry(user_input)) if it’s an instance method, or explicitly import it if it’s standalone.

🤖 Prompt for AI Agents
In docs/config_entries_config_flow_handler.md around lines 449 to 450, the call
to _validate_subentry is unqualified and will cause a NameError. Fix this by
prefixing the call with self. to make it await
self._validate_subentry(user_input) if _validate_subentry is an instance method,
or import it explicitly if it is a standalone function.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant