Migrate core from threads to async awesomeness (#3248)
* Add event loop to the core * Add block_till_done to HA core object * Fix some tests * Linting core * Fix statemachine tests * Core test fixes * fix block_till_done to wait for loop and queue to empty * fix test_core for passing, and correct start/stop/block_till_done * Fix remote tests * Fix tests: block_till_done * Fix linting * Fix more tests * Fix final linting * Fix remote test * remove unnecessary import * reduce sleep to avoid slowing down the tests excessively * fix remaining tests to wait for non-threadsafe operations * Add async_ doc strings for event loop / coroutine info * Fix command line test to block for the right timeout * Fix py3.4.2 loop var access * Fix SERVICE_CALL_LIMIT being in effect for other tests * Fix lint errors * Fix lint error with proper placement * Fix slave start to not start a timer * Add asyncio compatible listeners. * Increase min Python version to 3.4.2 * Move async backports to util * Add backported async tests * Fix linting * Simplify Python version check * Fix lint * Remove unneeded try/except and queue listener appproriately. * Fix tuple vs. list unorderable error on version compare. * Fix version tests
This commit is contained in:
parent
24f1bff7f1
commit
609d7ebea5
98 changed files with 1680 additions and 1109 deletions
|
@ -42,21 +42,21 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 9 is below 10
|
||||
self.hass.states.set('test.entity', 9)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
# Set above 12 so the automation will fire again
|
||||
self.hass.states.set('test.entity', 12)
|
||||
automation.turn_off(self.hass)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.hass.states.set('test.entity', 9)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_over_to_below(self):
|
||||
""""Test the firing with changed entity."""
|
||||
self.hass.states.set('test.entity', 11)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
|
@ -73,13 +73,13 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
|
||||
# 9 is below 10
|
||||
self.hass.states.set('test.entity', 9)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_entity_change_below_to_below(self):
|
||||
""""Test the firing with changed entity."""
|
||||
self.hass.states.set('test.entity', 9)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
|
@ -96,7 +96,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
|
||||
# 9 is below 10 so this should not fire again
|
||||
self.hass.states.set('test.entity', 8)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_above(self):
|
||||
|
@ -115,14 +115,14 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 11 is above 10
|
||||
self.hass.states.set('test.entity', 11)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_below_to_above(self):
|
||||
""""Test the firing with changed entity."""
|
||||
# set initial state
|
||||
self.hass.states.set('test.entity', 9)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
|
@ -139,14 +139,14 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
|
||||
# 11 is above 10 and 9 is below
|
||||
self.hass.states.set('test.entity', 11)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_entity_change_above_to_above(self):
|
||||
""""Test the firing with changed entity."""
|
||||
# set initial state
|
||||
self.hass.states.set('test.entity', 11)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
|
@ -163,7 +163,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
|
||||
# 11 is above 10 so this should fire again
|
||||
self.hass.states.set('test.entity', 12)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_below_range(self):
|
||||
|
@ -183,7 +183,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 9 is below 10
|
||||
self.hass.states.set('test.entity', 9)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_below_above_range(self):
|
||||
|
@ -203,13 +203,13 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 4 is below 5
|
||||
self.hass.states.set('test.entity', 4)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_over_to_below_range(self):
|
||||
""""Test the firing with changed entity."""
|
||||
self.hass.states.set('test.entity', 11)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
|
@ -227,13 +227,13 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
|
||||
# 9 is below 10
|
||||
self.hass.states.set('test.entity', 9)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_over_to_below_above_range(self):
|
||||
""""Test the firing with changed entity."""
|
||||
self.hass.states.set('test.entity', 11)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert _setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: {
|
||||
|
@ -251,7 +251,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
|
||||
# 4 is below 5 so it should not fire
|
||||
self.hass.states.set('test.entity', 4)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_not_fires_if_entity_not_match(self):
|
||||
|
@ -270,7 +270,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
|
||||
self.hass.states.set('test.entity', 11)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_fires_on_entity_change_below_with_attribute(self):
|
||||
|
@ -289,7 +289,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 9 is below 10
|
||||
self.hass.states.set('test.entity', 9, {'test_attribute': 11})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_entity_change_not_below_with_attribute(self):
|
||||
|
@ -308,7 +308,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 11 is not below 10
|
||||
self.hass.states.set('test.entity', 11, {'test_attribute': 9})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_fires_on_attribute_change_with_attribute_below(self):
|
||||
|
@ -328,7 +328,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 9 is below 10
|
||||
self.hass.states.set('test.entity', 'entity', {'test_attribute': 9})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_attribute_change_with_attribute_not_below(self):
|
||||
|
@ -348,7 +348,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 11 is not below 10
|
||||
self.hass.states.set('test.entity', 'entity', {'test_attribute': 11})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_entity_change_with_attribute_below(self):
|
||||
|
@ -368,7 +368,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 11 is not below 10, entity state value should not be tested
|
||||
self.hass.states.set('test.entity', '9', {'test_attribute': 11})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_entity_change_with_not_attribute_below(self):
|
||||
|
@ -388,7 +388,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
# 11 is not below 10, entity state value should not be tested
|
||||
self.hass.states.set('test.entity', 'entity')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_fires_on_attr_change_with_attribute_below_and_multiple_attr(self):
|
||||
|
@ -409,7 +409,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
# 9 is not below 10
|
||||
self.hass.states.set('test.entity', 'entity',
|
||||
{'test_attribute': 9, 'not_test_attribute': 11})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_template_list(self):
|
||||
|
@ -431,7 +431,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
# 3 is below 10
|
||||
self.hass.states.set('test.entity', 'entity',
|
||||
{'test_attribute': [11, 15, 3]})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_template_string(self):
|
||||
|
@ -457,10 +457,10 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
})
|
||||
self.hass.states.set('test.entity', 'test state 1',
|
||||
{'test_attribute': '1.2'})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.hass.states.set('test.entity', 'test state 2',
|
||||
{'test_attribute': '0.9'})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
self.assertEqual(
|
||||
'numeric_state - test.entity - 10.0 - None - test state 1 - '
|
||||
|
@ -485,7 +485,7 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
# 11 is not below 10
|
||||
self.hass.states.set('test.entity', 'entity',
|
||||
{'test_attribute': 11, 'not_test_attribute': 9})
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_action(self):
|
||||
|
@ -512,18 +512,18 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
|
||||
self.hass.states.set(entity_id, test_state)
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
self.hass.states.set(entity_id, test_state - 1)
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
self.hass.states.set(entity_id, test_state + 1)
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(2, len(self.calls))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue