Async bootstrap / component init (#3991)

* Async bootstrap

* Adress comments

* Fix tests

* More fixes

* Tests fixes
This commit is contained in:
Pascal Vizeli authored and Paulus Schoutsen committed 2016-10-27 00:16:23 -07:00
1 parent d9999f36e8
commit d5368f6f78
54 files changed
+1431 -1131

No files matched your search

+4 -4
View File
@@ -1,7 +1,7 @@
"""The tests for the MQTT binary sensor platform."""
import unittest
from homeassistant.bootstrap import _setup_component
from homeassistant.bootstrap import setup_component
import homeassistant.components.binary_sensor as binary_sensor
from tests.common import mock_mqtt_component, fire_mqtt_message
from homeassistant.const import (STATE_OFF, STATE_ON)
@@ -24,7 +24,7 @@ class TestSensorMQTT(unittest.TestCase):
def test_setting_sensor_value_via_mqtt_message(self):
"""Test the setting of the value via MQTT."""
self.hass.config.components = ['mqtt']
assert _setup_component(self.hass, binary_sensor.DOMAIN, {
assert setup_component(self.hass, binary_sensor.DOMAIN, {
binary_sensor.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
@@ -50,7 +50,7 @@ class TestSensorMQTT(unittest.TestCase):
def test_valid_sensor_class(self):
"""Test the setting of a valid sensor class."""
self.hass.config.components = ['mqtt']
assert _setup_component(self.hass, binary_sensor.DOMAIN, {
assert setup_component(self.hass, binary_sensor.DOMAIN, {
binary_sensor.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
@@ -65,7 +65,7 @@ class TestSensorMQTT(unittest.TestCase):
def test_invalid_sensor_class(self):
"""Test the setting of an invalid sensor class."""
self.hass.config.components = ['mqtt']
assert _setup_component(self.hass, binary_sensor.DOMAIN, {
assert setup_component(self.hass, binary_sensor.DOMAIN, {
binary_sensor.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
+10 -9
View File
@@ -8,6 +8,8 @@ from nx584 import client as nx584_client
from homeassistant.components.binary_sensor import nx584
from homeassistant.bootstrap import setup_component
from tests.common import get_test_home_assistant
class StopMe(Exception):
"""Stop helper."""
@@ -20,6 +22,7 @@ class TestNX584SensorSetup(unittest.TestCase):
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self._mock_client = mock.patch.object(nx584_client, 'Client')
self._mock_client.start()
@@ -35,6 +38,7 @@ class TestNX584SensorSetup(unittest.TestCase):
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
self._mock_client.stop()
@mock.patch('homeassistant.components.binary_sensor.nx584.NX584Watcher')
@@ -42,14 +46,13 @@ class TestNX584SensorSetup(unittest.TestCase):
def test_setup_defaults(self, mock_nx, mock_watcher):
"""Test the setup with no configuration."""
add_devices = mock.MagicMock()
hass = mock.MagicMock()
config = {
'host': nx584.DEFAULT_HOST,
'port': nx584.DEFAULT_PORT,
'exclude_zones': [],
'zone_types': {},
}
self.assertTrue(nx584.setup_platform(hass, config, add_devices))
self.assertTrue(nx584.setup_platform(self.hass, config, add_devices))
mock_nx.assert_has_calls(
[mock.call(zone, 'opening') for zone in self.fake_zones])
self.assertTrue(add_devices.called)
@@ -69,8 +72,7 @@ class TestNX584SensorSetup(unittest.TestCase):
'zone_types': {3: 'motion'},
}
add_devices = mock.MagicMock()
hass = mock.MagicMock()
self.assertTrue(nx584.setup_platform(hass, config, add_devices))
self.assertTrue(nx584.setup_platform(self.hass, config, add_devices))
mock_nx.assert_has_calls([
mock.call(self.fake_zones[0], 'opening'),
mock.call(self.fake_zones[2], 'motion'),
@@ -84,9 +86,8 @@ class TestNX584SensorSetup(unittest.TestCase):
def _test_assert_graceful_fail(self, config):
"""Test the failing."""
hass = add_devices = mock.MagicMock()
self.assertFalse(setup_component(hass, 'binary_sensor.nx584', config))
self.assertFalse(add_devices.called)
self.assertFalse(setup_component(
self.hass, 'binary_sensor.nx584', config))
def test_setup_bad_config(self):
"""Test the setup with bad configuration."""
@@ -113,8 +114,8 @@ class TestNX584SensorSetup(unittest.TestCase):
def test_setup_no_zones(self):
"""Test the setup with no zones."""
nx584_client.Client.return_value.list_zones.return_value = []
hass = add_devices = mock.MagicMock()
self.assertTrue(nx584.setup_platform(hass, {}, add_devices))
add_devices = mock.MagicMock()
self.assertTrue(nx584.setup_platform(self.hass, {}, add_devices))
self.assertFalse(add_devices.called)