Skip to content

Conversation

@victorigualada
Copy link
Contributor

Proposed change

This PR adds the ability to reorder the device picker in automations based on the automation context. My idea was to follow the locality principle to allow faster automation creation.

It adds a Lit context to store the automation devices, entities and areas in order to pass down those values to the pickers so the lists can be reordered based on them.

I added a bigger context schema than needed for this PR just to discuss how it could be extended. This is intended as a minimal feature.

imagen

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

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

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

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

Object.values(this._configSubscriptions).forEach((sub) =>
sub(this._config)
);
const ctx = buildAutomationLocalContext(
Copy link
Member

Choose a reason for hiding this comment

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

I would like to prevent this from re-creating everything when the automation changes, as it will trigger the other memoized functions to also recalculate. Can we make sure to only update those parts that actually changed? So if no devices changed, we don't recreate used.devices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a signature to the context that we can compare on change updates to not update the context object.


const suggestedPrefix = suggestedDevices?.includes(device.id)
? "0|"
: "1|";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bramkragten This is hacky but I didn't want to increase the scope of the PR nor know how you would approach an alternative. In my mind this would be replaced by a proper grouping like “Suggested” and “All devices” or something similar.

@victorigualada victorigualada marked this pull request as ready for review October 13, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants