Sort entities in default groups by name (#7681)

* Sort entities in default groups by name

* Cleanups from review
This commit is contained in:
Anders Melchiorsen 2017-05-22 02:05:48 +02:00 committed by Paulus Schoutsen
parent b3cb057aac
commit bb8de5845a
2 changed files with 8 additions and 7 deletions

View file

@ -232,12 +232,12 @@ class EntityComponent(object):
if self.group is None and self.group_name is not None:
group = get_component('group')
self.group = yield from group.Group.async_create_group(
self.hass, self.group_name, self.entities.keys(),
user_defined=False
)
self.hass, self.group_name,
sorted(self.entities, key=lambda x: self.entities[x].name),
user_defined=False)
elif self.group is not None:
yield from self.group.async_update_tracked_entity_ids(
self.entities.keys())
sorted(self.entities, key=lambda x: self.entities[x].name))
def reset(self):
"""Remove entities and reset the entity component to initial values."""

View file

@ -92,13 +92,14 @@ class TestHelpersEntityComponent(unittest.TestCase):
assert group.attributes.get('entity_id') == ('test_domain.hello',)
# group extended
component.add_entities([EntityTest(name='hello2')])
component.add_entities([EntityTest(name='goodbye')])
assert len(self.hass.states.entity_ids()) == 3
group = self.hass.states.get('group.everyone')
assert sorted(group.attributes.get('entity_id')) == \
['test_domain.hello', 'test_domain.hello2']
# Sorted order
assert group.attributes.get('entity_id') == \
('test_domain.goodbye', 'test_domain.hello')
def test_polling_only_updates_entities_it_should_poll(self):
"""Test the polling of only updated entities."""