From 18935440edaf8e5f1d9bb7a3e6432f606c700fde Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 17 Jun 2017 10:50:59 -0700 Subject: [PATCH] Fix EntityComponent handle entities without a name (#8065) * Fix EntityComponent handle entities without a name * Implement solution by Anders --- homeassistant/helpers/entity_component.py | 3 ++- tests/helpers/test_entity_component.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index f7cf23b21fd..8cfc9984e2e 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -238,7 +238,8 @@ class EntityComponent(object): This method must be run in the event loop. """ if self.group_name is not None: - ids = sorted(self.entities, key=lambda x: self.entities[x].name) + ids = sorted(self.entities, + key=lambda x: self.entities[x].name or x) group = get_component('group') group.async_set_group( self.hass, slugify(self.group_name), name=self.group_name, diff --git a/tests/helpers/test_entity_component.py b/tests/helpers/test_entity_component.py index 530e2662083..f68090358c7 100644 --- a/tests/helpers/test_entity_component.py +++ b/tests/helpers/test_entity_component.py @@ -84,7 +84,7 @@ class TestHelpersEntityComponent(unittest.TestCase): # No group after setup assert len(self.hass.states.entity_ids()) == 0 - component.add_entities([EntityTest(name='hello')]) + component.add_entities([EntityTest()]) # group exists assert len(self.hass.states.entity_ids()) == 2 @@ -92,7 +92,8 @@ class TestHelpersEntityComponent(unittest.TestCase): group = self.hass.states.get('group.everyone') - assert group.attributes.get('entity_id') == ('test_domain.hello',) + assert group.attributes.get('entity_id') == \ + ('test_domain.unnamed_device',) # group extended component.add_entities([EntityTest(name='goodbye')]) @@ -100,9 +101,9 @@ class TestHelpersEntityComponent(unittest.TestCase): assert len(self.hass.states.entity_ids()) == 3 group = self.hass.states.get('group.everyone') - # Sorted order + # Ordered in order of added to the group assert group.attributes.get('entity_id') == \ - ('test_domain.goodbye', 'test_domain.hello') + ('test_domain.goodbye', 'test_domain.unnamed_device') def test_polling_only_updates_entities_it_should_poll(self): """Test the polling of only updated entities."""