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

Add config subentry support to entity registry #128155

Merged

Conversation

emontnemery
Copy link
Contributor

@emontnemery emontnemery commented Oct 11, 2024

Proposed change

Add config subentry support to entity registry

This is intended as a follow-up to #117355

Needs #128157

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)
  • 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:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • 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:

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (config) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of config can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign config Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@emontnemery emontnemery force-pushed the entity_registry_subentry_support branch from 4842a7c to 8d6853d Compare December 2, 2024 08:06
@emontnemery
Copy link
Contributor Author

emontnemery commented Dec 12, 2024

Frontend is approved: home-assistant/frontend#23160

@emontnemery emontnemery force-pushed the entity_registry_subentry_support branch from 8d6853d to 23fc272 Compare December 12, 2024 19:17
@emontnemery emontnemery force-pushed the entity_registry_subentry_support branch from 23fc272 to 242226b Compare December 14, 2024 10:37
@emontnemery emontnemery force-pushed the entity_registry_subentry_support branch from 242226b to 7292531 Compare December 18, 2024 09:13
@emontnemery emontnemery force-pushed the entity_registry_subentry_support branch from 7292531 to 048e642 Compare January 23, 2025 19:13
@emontnemery emontnemery changed the base branch from dev to config_subentries_feature_2 January 23, 2025 19:13
@emontnemery emontnemery marked this pull request as ready for review January 23, 2025 19:13
homeassistant/helpers/entity_registry.py Outdated Show resolved Hide resolved
@@ -1431,7 +1562,7 @@ async def test_remove_config_entry_from_device_removes_entities_2(
config_entry_2.entry_id,
}

# Create one entity for each config entry
# Create an entity without config entry
Copy link
Member

Choose a reason for hiding this comment

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

Side note: It's weird to have an entity entry connected to a device entry but not connected to the config entry of the device entry. Should that even be allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's indeed weird, and I think we should add validation to prevent it in a follow-up

tests/helpers/test_entity_registry.py Outdated Show resolved Hide resolved
"light",
"hue",
"5678",
device_id=device_entry.id,
Copy link
Member

Choose a reason for hiding this comment

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

When does an integration connect its entities to another integration's device without having a config entry of its own?

I was thinking maybe the template integration but that only links to devices when set up from a config entry.

The entity platform helper code doesn't support connecting a device via device_info if the added entity doesn't have a config entry.

The only place in our codebase I found that created an entity entry directly via async_get_or_create without a config entry was the TagEntity which doesn't connect to a device entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's probably no valid case, I just added tests to assert behavior for various cases

@emontnemery emontnemery merged commit 313e82f into config_subentries_feature_2 Jan 27, 2025
46 checks passed
@emontnemery emontnemery deleted the entity_registry_subentry_support branch January 27, 2025 20:15
@github-actions github-actions bot locked and limited conversation to collaborators Jan 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants