Skip to content
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

Update unique-config-entry rule #2510

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

Conversation

joostlek
Copy link
Member

@joostlek joostlek commented Dec 19, 2024

Proposed change

The current unique-config-entry rule does not cover that a config flow started by the user should not be used to update data of an existing config entry. Instead, devs should implement and users should use the reconfiguration flow. This leaves for a more consistent user experience (since does setting up the device again update every field? Only the Host? Only the password? An end user can only guess).

So let's update the rule to mention that we don't want to re-use the config flow to change existing entry data.

Type of change

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

Additional information

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

Summary by CodeRabbit

  • Documentation
    • Updated guidelines to prevent duplicate device or service configurations in integrations.
    • Expanded reasoning on issues caused by duplicates, including identifier collisions and discovery complications.
    • Added a statement on blocking attempts to set up already configured devices or services.
    • Enhanced examples for ensuring unique configuration entries with detailed explanations of methods and checks.

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The documentation for handling unique configuration entries in integrations has been updated to provide clearer guidance on preventing duplicate device or service configurations. The document now offers more detailed explanations about why and how to block duplicate configurations, including two specific methods for ensuring uniqueness: using unique identifiers and checking specific configuration fields.

Changes

File Change Summary
docs/core/integration-quality-scale/rules/unique-config-entry.md Updated documentation with expanded reasoning for preventing duplicate configurations and added detailed examples of implementation methods for ensuring unique configuration entries

Sequence Diagram

sequenceDiagram
    participant Integration
    participant ConfigFlow
    participant ExistingConfigs

    Integration->>ConfigFlow: Attempt to create new configuration
    ConfigFlow->>ExistingConfigs: Check for existing unique ID
    alt Unique ID already exists
        ConfigFlow-->>Integration: Abort configuration flow
    else Unique ID is new
        ConfigFlow->>ExistingConfigs: Check specific config fields
        alt Matching config fields found
            ConfigFlow-->>Integration: Abort configuration flow
        else No matching config found
            ConfigFlow->>ExistingConfigs: Create new configuration
        end
    end
Loading

The sequence diagram illustrates the process of checking for unique configuration entries, showing how an integration would validate and prevent duplicate configurations through checks on unique identifiers and specific configuration fields.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8217581 and 9abb060.

📒 Files selected for processing (1)
  • docs/core/integration-quality-scale/rules/unique-config-entry.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/core/integration-quality-scale/rules/unique-config-entry.md

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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: 0

🧹 Nitpick comments (1)
docs/core/integration-quality-scale/rules/unique-config-entry.md (1)

20-21: LGTM! Clear improvement to the documentation.

The added text effectively clarifies that modifications to existing configurations should be handled through reconfiguration flows rather than the initial configuration flow. This helps prevent confusion about which fields get updated during reconfiguration.

Consider adding an example implementation of a reconfiguration flow to complement the existing examples, demonstrating how to properly handle updates to an existing configuration entry. This would provide a complete picture of the recommended approach.

Example structure to consider adding:

### Reconfiguration flow

When a user needs to modify an existing configuration (e.g., update credentials or connection details), use a reconfiguration flow instead of the initial configuration flow. This ensures clarity about which fields are being updated.

Example implementation of a reconfiguration flow:
[code example here]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4520e57 and 8217581.

📒 Files selected for processing (1)
  • docs/core/integration-quality-scale/rules/unique-config-entry.md (1 hunks)

@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft December 19, 2024 15:07
@joostlek joostlek marked this pull request as ready for review December 19, 2024 15:29
@home-assistant home-assistant bot requested a review from abmantis December 19, 2024 15:29
@@ -17,6 +17,8 @@ This can lead to duplicated devices and entities with unique identifiers collidi
Any discovery flow must also ensure that a config entry is uniquely identifiable, as otherwise, it would discover devices already set up.

To prevent this, we need to ensure that the user can only set up a device or service once.
Trying to set up a device or service that is already set up should be prevented by the integration.
If an update to the configuration is required, it should be handled by the reconfiguration flow instead, as it allows us to be more consistent with what gets updated.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this discuss reauth as the only exception to this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, the goal is to disallow starting a config flow manually and then trying to setup the same device and automatically update things like the host and port. Not necessarily to only allow the reconfigure flow to update the config. (like, we still want to update the entry via code if needed, so I don't want to slam that door closed)

Copy link
Contributor

Choose a reason for hiding this comment

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

True, I don't intend to suggest that reauth should be updating configuration outside of authentication credentials. I was thrown off by the phrase "update to the configuration" which sounds broad, but i understand you're implicitly allowing an exception for authentication parts of the configuration.

Copy link
Member Author

Choose a reason for hiding this comment

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

But you are a native English speaker, so if you have improvements to convey this better, please let me know 🙏🏻

Comment on lines +20 to +21
Trying to set up a device or service that is already set up should be prevented by the integration.
If an update to the configuration is required, it should be handled by the reconfiguration flow instead, as it allows us to be more consistent with what gets updated.
Copy link
Contributor

@allenporter allenporter Dec 19, 2024

Choose a reason for hiding this comment

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

Yes, though I also learned that means my english is sloppy and less precise :)

That said, this is how I understand it:

Suggested change
Trying to set up a device or service that is already set up should be prevented by the integration.
If an update to the configuration is required, it should be handled by the reconfiguration flow instead, as it allows us to be more consistent with what gets updated.
Updates to an existing device or service configuration are only allowed through the reconfiguration flow. Updates to authentication credentials are allowed in a reauthentication flow. Otherwise, trying to set up a device or service that is already set up should be prevented by the integration.

@@ -17,6 +17,8 @@ This can lead to duplicated devices and entities with unique identifiers collidi
Any discovery flow must also ensure that a config entry is uniquely identifiable, as otherwise, it would discover devices already set up.

To prevent this, we need to ensure that the user can only set up a device or service once.
Trying to set up a device or service that is already set up should be prevented by the integration.
If an update to the configuration is required, it should be handled by the reconfiguration flow instead, as it allows us to be more consistent with what gets updated.
Copy link
Member

Choose a reason for hiding this comment

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

How about this as an alternative:

Suggested change
If an update to the configuration is required, it should be handled by the reconfiguration flow instead, as it allows us to be more consistent with what gets updated.
Configuration flows initiated manually by the user to set up a new entry should not modify or update existing configuration entries. For these purposes, we have our discovery, options, and reconfiguration flows available instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

So to set the terms straight, what do we use Configuration flows for? because all flows like discovery, options, reauth and reconfigure flow are in theory configuration flows right?

Because with that in mind, the reconfigure flow is also a configuration flow initiated by the user

Copy link
Member

@frenck frenck Dec 19, 2024

Choose a reason for hiding this comment

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

Yes: Hence, with the intention to set up a new entry being mentioned there. This will also fit the bill for anything that comes down road regarding nuggets, that also cause new entries.

Basically, we want to prevent existing entries from being modified while the user had the intention of creating a new entry.

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.

4 participants