mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
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:
committed by
Ben Bangert
parent
24f1bff7f1
commit
609d7ebea5
@@ -42,14 +42,14 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
automation.turn_off(self.hass)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.hass.states.set('test.entity', 'planet')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_change_str(self):
|
||||
@@ -67,7 +67,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_change_str_crazy(self):
|
||||
@@ -85,7 +85,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_change_bool(self):
|
||||
@@ -103,7 +103,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_change_str(self):
|
||||
@@ -121,7 +121,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_change_str_crazy(self):
|
||||
@@ -139,7 +139,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_fires_on_no_change(self):
|
||||
@@ -156,11 +156,11 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.calls = []
|
||||
|
||||
self.hass.states.set('test.entity', 'hello')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_fires_on_two_change(self):
|
||||
@@ -179,12 +179,12 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
# Trigger once
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
# Trigger again
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_change_with_template(self):
|
||||
@@ -202,7 +202,7 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_not_fires_on_change_with_template(self):
|
||||
@@ -219,11 +219,11 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.calls = []
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 0
|
||||
|
||||
def test_if_fires_on_change_with_template_advanced(self):
|
||||
@@ -250,11 +250,11 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.calls = []
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
self.assertEqual(
|
||||
'template - test.entity - hello - world',
|
||||
@@ -280,12 +280,12 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
# Different state
|
||||
self.hass.states.set('test.entity', 'worldz')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
# Different state
|
||||
self.hass.states.set('test.entity', 'hello')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_if_fires_on_change_with_template_2(self):
|
||||
@@ -303,31 +303,31 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.calls = []
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 0
|
||||
|
||||
self.hass.states.set('test.entity', 'home')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 1
|
||||
|
||||
self.hass.states.set('test.entity', 'work')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 1
|
||||
|
||||
self.hass.states.set('test.entity', 'not_home')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 1
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 1
|
||||
|
||||
self.hass.states.set('test.entity', 'home')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
assert len(self.calls) == 2
|
||||
|
||||
def test_if_action(self):
|
||||
@@ -350,17 +350,17 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
|
||||
# Condition is not true yet
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
# Change condition to true, but it shouldn't be triggered yet
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
# Condition is true and event is triggered
|
||||
self.hass.bus.fire('test_event')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
|
||||
def test_if_fires_on_change_with_bad_template(self):
|
||||
@@ -392,5 +392,5 @@ class TestAutomationTemplate(unittest.TestCase):
|
||||
})
|
||||
|
||||
self.hass.states.set('test.entity', 'world')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
Reference in New Issue
Block a user