Skip to content

Sort entities in default groups by name#7681

Merged
balloob merged 2 commits into
home-assistant:devfrom
amelchio:sort-default-groups
May 22, 2017
Merged

Sort entities in default groups by name#7681
balloob merged 2 commits into
home-assistant:devfrom
amelchio:sort-default-groups

Conversation

@amelchio
Copy link
Copy Markdown
Contributor

Description:

When used in a frontend view, having things like group.all_scripts assume a new random order on each restart is annoying. This sorts them by name instead.

Related issue (if applicable): fixes #6557

Example entry for configuration.yaml (if applicable):

group:
  default_view:
    name: Admin
    view: yes
    entities:
      - group.all_automations
      - group.all_scripts

Checklist:

If the code does not interact with devices:

  • Local tests with tox run successfully.
  • Tests have been added to verify that the new code works.

@mention-bot
Copy link
Copy Markdown

@amelchio, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @pvizeli to be potential reviewers.


This method must be run in the event loop.
"""
def sorted_ids():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We shouldn't instantiate a method on each call to this method. Instead just copy paste the method in both places.

You should also be able to do just this: sorted(self.entities, key=lambda x: self.entities.name)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, that key extraction ended up a bit redundant. I inlined the short version now.

@balloob balloob merged commit bb8de58 into home-assistant:dev May 22, 2017
@balloob balloob mentioned this pull request Jun 2, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Sep 4, 2017
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.

Scripts and automations not sorted with custom default_view

5 participants