Async EntitiesComponent (#3820)

* first version

* First draft component entities

* Change add_entities to callback from coroutine

* Fix bug add async_prepare_reload

* Group draft v1

* group async

* bugfix

* bugfix v2

* fix lint

* fix extract_entity_ids

* fix other things

* move get_component out of executor

* bugfix

* Address minor changes

* lint

* bugfix - should work now

* make group init async only

* change update handling to old stuff

* fix group handling, remove generator from init

* fix lint

* protect loop for spaming with updates

* fix lint

* update test_group

* fix

* update group handling

* fix __init__ async trouble

* move device_tracker to new layout

* lint

* fix group unittest

* Test with coroutine

* fix bug

* now it works 💯

* ups

* first part of suggestion

* add_entities to coroutine

* change group

* convert add async_add_entity to coroutine

* fix unit tests

* fix lint

* fix lint part 2

* fix wrong import delete

* change async_update_tracked_entity_ids to coroutine

* fix

* revert last change

* fix unittest entity id

* fix unittest

* fix unittest

* fix unittest entity_component

* fix group

* fix group_test

* try part 2 to fix test_group

* fix all entity_component

* rename _process_config

* Change Group to init with factory

* fix lint

* fix lint

* fix callback

* Tweak entity component and group

* More fixes

* Final fixes

* No longer needed blocks

* Address @bbangert comments

* Add test for group.stop

* More callbacks for automation
This commit is contained in:
Pascal Vizeli authored and Paulus Schoutsen committed 2016-10-16 09:35:46 -07:00
1 parent a0fdb2778d
commit 0b8b9ecb94
14 files changed
+503 -266

No files matched your search

+18 -24
View File
@@ -9,11 +9,22 @@ from uvcclient import nvr
from homeassistant.bootstrap import setup_component
from homeassistant.components.camera import uvc
from tests.common import get_test_home_assistant
class TestUVCSetup(unittest.TestCase):
"""Test the UVC camera platform."""
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.wsgi = mock.MagicMock()
self.hass.config.components = ['http']
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
@mock.patch('uvcclient.nvr.UVCRemote')
@mock.patch.object(uvc, 'UnifiVideoCamera')
def test_setup_full_config(self, mock_uvc, mock_remote):
@@ -37,14 +48,11 @@ class TestUVCSetup(unittest.TestCase):
else:
return {'model': 'UVC'}
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
mock_remote.return_value.index.return_value = fake_cameras
mock_remote.return_value.get_camera.side_effect = fake_get_camera
mock_remote.return_value.server_version = (3, 2, 0)
assert setup_component(hass, 'camera', {'camera': config})
assert setup_component(self.hass, 'camera', {'camera': config})
mock_remote.assert_called_once_with('foo', 123, 'secret')
mock_uvc.assert_has_calls([
@@ -65,14 +73,11 @@ class TestUVCSetup(unittest.TestCase):
{'uuid': 'one', 'name': 'Front', 'id': 'id1'},
{'uuid': 'two', 'name': 'Back', 'id': 'id2'},
]
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
mock_remote.return_value.index.return_value = fake_cameras
mock_remote.return_value.get_camera.return_value = {'model': 'UVC'}
mock_remote.return_value.server_version = (3, 2, 0)
assert setup_component(hass, 'camera', {'camera': config})
assert setup_component(self.hass, 'camera', {'camera': config})
mock_remote.assert_called_once_with('foo', 7080, 'secret')
mock_uvc.assert_has_calls([
@@ -93,14 +98,11 @@ class TestUVCSetup(unittest.TestCase):
{'uuid': 'one', 'name': 'Front', 'id': 'id1'},
{'uuid': 'two', 'name': 'Back', 'id': 'id2'},
]
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
mock_remote.return_value.index.return_value = fake_cameras
mock_remote.return_value.get_camera.return_value = {'model': 'UVC'}
mock_remote.return_value.server_version = (3, 1, 3)
assert setup_component(hass, 'camera', {'camera': config})
assert setup_component(self.hass, 'camera', {'camera': config})
mock_remote.assert_called_once_with('foo', 7080, 'secret')
mock_uvc.assert_has_calls([
@@ -111,18 +113,14 @@ class TestUVCSetup(unittest.TestCase):
@mock.patch.object(uvc, 'UnifiVideoCamera')
def test_setup_incomplete_config(self, mock_uvc):
""""Test the setup with incomplete configuration."""
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
assert setup_component(
hass, 'camera', {'platform': 'uvc', 'nvr': 'foo'})
self.hass, 'camera', {'platform': 'uvc', 'nvr': 'foo'})
assert not mock_uvc.called
assert setup_component(
hass, 'camera', {'platform': 'uvc', 'key': 'secret'})
self.hass, 'camera', {'platform': 'uvc', 'key': 'secret'})
assert not mock_uvc.called
assert setup_component(
hass, 'camera', {'platform': 'uvc', 'port': 'invalid'})
self.hass, 'camera', {'platform': 'uvc', 'port': 'invalid'})
assert not mock_uvc.called
@mock.patch.object(uvc, 'UnifiVideoCamera')
@@ -136,13 +134,9 @@ class TestUVCSetup(unittest.TestCase):
'nvr': 'foo',
'key': 'secret',
}
hass = mock.MagicMock()
hass.pool.worker_count = 2
hass.config.components = ['http']
for error in errors:
mock_remote.return_value.index.side_effect = error
assert setup_component(hass, 'camera', config)
assert setup_component(self.hass, 'camera', config)
assert not mock_uvc.called