diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index 6e69f772d1e..2c1801a6342 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -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.""" diff --git a/tests/helpers/test_entity_component.py b/tests/helpers/test_entity_component.py index a76b3a15068..ade8c4ebd8a 100644 --- a/tests/helpers/test_entity_component.py +++ b/tests/helpers/test_entity_component.py @@ -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."""