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

+37 -34
View File
@@ -3,11 +3,12 @@ from datetime import timedelta
import unittest
from unittest.mock import patch
from homeassistant.bootstrap import _setup_component
from homeassistant.bootstrap import setup_component
import homeassistant.util.dt as dt_util
import homeassistant.components.automation as automation
from tests.common import fire_time_changed, get_test_home_assistant
from tests.common import (
fire_time_changed, get_test_home_assistant, assert_setup_component)
class TestAutomationTime(unittest.TestCase):
@@ -30,7 +31,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_fires_when_hour_matches(self):
"""Test for firing if hour is matching."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
@@ -55,7 +56,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_fires_when_minute_matches(self):
"""Test for firing if minutes are matching."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
@@ -74,7 +75,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_fires_when_second_matches(self):
"""Test for firing if seconds are matching."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
@@ -93,7 +94,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_fires_when_all_matches(self):
"""Test for firing if everything matches."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
@@ -115,7 +116,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_fires_periodic_seconds(self):
"""Test for firing periodically every second."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
@@ -135,7 +136,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_fires_periodic_minutes(self):
"""Test for firing periodically every minute."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
@@ -155,7 +156,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_fires_periodic_hours(self):
"""Test for firing periodically every hour."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
@@ -175,7 +176,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_fires_using_after(self):
"""Test for firing after."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
@@ -200,16 +201,17 @@ class TestAutomationTime(unittest.TestCase):
def test_if_not_working_if_no_values_in_conf_provided(self):
"""Test for failure if no configuration."""
assert not _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
},
'action': {
'service': 'test.automation'
with assert_setup_component(0):
assert not setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
},
'action': {
'service': 'test.automation'
}
}
}
})
})
fire_time_changed(self.hass, dt_util.utcnow().replace(
hour=5, minute=0, second=0))
@@ -222,18 +224,19 @@ class TestAutomationTime(unittest.TestCase):
This should break the before rule.
"""
assert not _setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'after': 3605,
# Total seconds. Hour = 3600 second
},
'action': {
'service': 'test.automation'
with assert_setup_component(0):
assert not setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time',
'after': 3605,
# Total seconds. Hour = 3600 second
},
'action': {
'service': 'test.automation'
}
}
}
})
})
fire_time_changed(self.hass, dt_util.utcnow().replace(
hour=1, minute=0, second=5))
@@ -243,7 +246,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_action_before(self):
"""Test for if action before."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',
@@ -278,7 +281,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_action_after(self):
"""Test for if action after."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',
@@ -313,7 +316,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_action_one_weekday(self):
"""Test for if action with one weekday."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',
@@ -349,7 +352,7 @@ class TestAutomationTime(unittest.TestCase):
def test_if_action_list_weekday(self):
"""Test for action with a list of weekdays."""
assert _setup_component(self.hass, automation.DOMAIN, {
assert setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'event',