Clean up entity component (#11691)
* Clean up entity component * Lint * List -> Tuple * Add Entity.async_remove back * Unflake setting up group test
This commit is contained in:
1 parent
d478517c51
commit
183e0543b4
14 files changed
+230
-191
No files matched your search
@@ -350,7 +350,7 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
|
||||
assert sorted(self.hass.states.entity_ids()) == \
|
||||
['group.empty_group', 'group.second_group', 'group.test_group']
|
||||
assert self.hass.bus.listeners['state_changed'] == 3
|
||||
assert self.hass.bus.listeners['state_changed'] == 2
|
||||
|
||||
with patch('homeassistant.config.load_yaml_config_file', return_value={
|
||||
'group': {
|
||||
@@ -365,14 +365,6 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
assert self.hass.states.entity_ids() == ['group.hello']
|
||||
assert self.hass.bus.listeners['state_changed'] == 1
|
||||
|
||||
def test_stopping_a_group(self):
|
||||
"""Test that a group correctly removes itself."""
|
||||
grp = group.Group.create_group(
|
||||
self.hass, 'light', ['light.test_1', 'light.test_2'])
|
||||
assert self.hass.states.entity_ids() == ['group.light']
|
||||
grp.stop()
|
||||
assert self.hass.states.entity_ids() == []
|
||||
|
||||
def test_changing_group_visibility(self):
|
||||
"""Test that a group can be hidden and shown."""
|
||||
assert setup_component(self.hass, 'group', {
|
||||
|
||||
@@ -388,3 +388,15 @@ def test_async_pararell_updates_with_two(hass):
|
||||
test_lock.release()
|
||||
yield from asyncio.sleep(0, loop=hass.loop)
|
||||
test_lock.release()
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_async_remove_no_platform(hass):
|
||||
"""Test async_remove method when no platform set."""
|
||||
ent = entity.Entity()
|
||||
ent.hass = hass
|
||||
ent.entity_id = 'test.test'
|
||||
yield from ent.async_update_ha_state()
|
||||
assert len(hass.states.async_entity_ids()) == 1
|
||||
yield from ent.async_remove()
|
||||
assert len(hass.states.async_entity_ids()) == 0
|
||||
@@ -86,6 +86,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
||||
assert len(self.hass.states.entity_ids()) == 0
|
||||
|
||||
component.add_entities([EntityTest()])
|
||||
self.hass.block_till_done()
|
||||
|
||||
# group exists
|
||||
assert len(self.hass.states.entity_ids()) == 2
|
||||
@@ -98,6 +99,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
||||
|
||||
# group extended
|
||||
component.add_entities([EntityTest(name='goodbye')])
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(self.hass.states.entity_ids()) == 3
|
||||
group = self.hass.states.get('group.everyone')
|
||||
@@ -214,7 +216,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
||||
|
||||
assert 0 == len(self.hass.states.entity_ids())
|
||||
|
||||
component.add_entities([None, EntityTest(unique_id='not_very_unique')])
|
||||
component.add_entities([EntityTest(unique_id='not_very_unique')])
|
||||
|
||||
assert 1 == len(self.hass.states.entity_ids())
|
||||
|
||||
@@ -671,3 +673,14 @@ def test_raise_error_on_update(hass):
|
||||
|
||||
assert len(updates) == 1
|
||||
assert 1 in updates
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_async_remove_with_platform(hass):
|
||||
"""Remove an entity from a platform."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
entity1 = EntityTest(name='test_1')
|
||||
yield from component.async_add_entities([entity1])
|
||||
assert len(hass.states.async_entity_ids()) == 1
|
||||
yield from entity1.async_remove()
|
||||
assert len(hass.states.async_entity_ids()) == 0
|
||||
Reference in new issue
Block a user