Skip to content

Extract triggers/conditions/services for non-primary entities#169319

Closed
abmantis wants to merge 387 commits intonon_primary_entity_conditions2from
automation_components_diag_entities
Closed

Extract triggers/conditions/services for non-primary entities#169319
abmantis wants to merge 387 commits intonon_primary_entity_conditions2from
automation_components_diag_entities

Conversation

@abmantis
Copy link
Copy Markdown
Member

@abmantis abmantis commented Apr 27, 2026

Proposed change

Make get_triggers_for_target/get_conditions_for_target/get_services_for_target expose triggers/conditions/services with primary_entities_only=False when there are matching non-primary entities.
This keeps the existing behavior for when there are no indirect targets: all triggers/conditions/services are returned, regardless of the flag.

Implements #168101.

Depends on #169291.

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

Checklist

  • I understand the code I am submitting and can explain how it works.
  • 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.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

agners and others added 30 commits April 24, 2026 18:09
…68756)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: TheJulianJES <TheJulianJES@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…#168209)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
…IMAP connection was lost (#168662)

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: RaHehl <rahehl@users.noreply.github.com>
gjohansson-ST and others added 20 commits April 29, 2026 09:14
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Franck Nijhof <git@frenck.dev>
…NS (#169240)

Co-authored-by: Claude Code <claude@anthropic.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
…169326)

Co-authored-by: Andrej Walilko <awalilko@liquidweb.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines +133 to +136
if check_entity_category and self.primary_entities_only:
entry = er.async_get(hass).async_get(entity_id)
if entry is None or entry.entity_category is not None:
return False
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

Cache entity registry lookups per entity (or precompute a set of non-primary entity_ids) before iterating components to avoid doing an entity registry lookup for every component filter check, which can become expensive for large targets and many component descriptions.

Copilot uses AI. Check for mistakes.
Comment on lines 250 to 279
@@ -253,7 +271,11 @@ def _async_get_automation_components_for_target(
if component_data.component in matched_components:
continue
if component_data.matches(
hass, entity_id, entity_domain, entity_integration
hass,
entity_id,
entity_domain,
entity_integration,
check_entity_category,
):
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

Apply the entity_category filter only to indirectly expanded entities (e.g., when entity_id is in extracted.indirectly_referenced) instead of enabling it globally whenever any indirect entity exists, to avoid changing behavior for explicitly targeted entities in mixed targets (and to avoid excluding non-registry entities when combined with area/device/label targets).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

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

Hi @daily063

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@abmantis abmantis requested a review from Copilot April 29, 2026 10:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@abmantis abmantis closed this Apr 29, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 30, 2026
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.