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:
1 parent
24f1bff7f1
commit
609d7ebea5
98 files changed
+1680
-1109
No files matched your search
@@ -56,7 +56,7 @@ class TestLight(unittest.TestCase):
|
||||
xy_color='xy_color_val',
|
||||
profile='profile_val')
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(turn_on_calls))
|
||||
call = turn_on_calls[-1]
|
||||
@@ -79,7 +79,7 @@ class TestLight(unittest.TestCase):
|
||||
light.turn_off(
|
||||
self.hass, entity_id='entity_id_val', transition='transition_val')
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(turn_off_calls))
|
||||
call = turn_off_calls[-1]
|
||||
@@ -96,7 +96,7 @@ class TestLight(unittest.TestCase):
|
||||
light.toggle(
|
||||
self.hass, entity_id='entity_id_val', transition='transition_val')
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(1, len(toggle_calls))
|
||||
call = toggle_calls[-1]
|
||||
@@ -125,7 +125,7 @@ class TestLight(unittest.TestCase):
|
||||
light.turn_off(self.hass, entity_id=dev1.entity_id)
|
||||
light.turn_on(self.hass, entity_id=dev2.entity_id)
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertFalse(light.is_on(self.hass, dev1.entity_id))
|
||||
self.assertTrue(light.is_on(self.hass, dev2.entity_id))
|
||||
@@ -133,7 +133,7 @@ class TestLight(unittest.TestCase):
|
||||
# turn on all lights
|
||||
light.turn_on(self.hass)
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertTrue(light.is_on(self.hass, dev1.entity_id))
|
||||
self.assertTrue(light.is_on(self.hass, dev2.entity_id))
|
||||
@@ -142,7 +142,7 @@ class TestLight(unittest.TestCase):
|
||||
# turn off all lights
|
||||
light.turn_off(self.hass)
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertFalse(light.is_on(self.hass, dev1.entity_id))
|
||||
self.assertFalse(light.is_on(self.hass, dev2.entity_id))
|
||||
@@ -151,7 +151,7 @@ class TestLight(unittest.TestCase):
|
||||
# toggle all lights
|
||||
light.toggle(self.hass)
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertTrue(light.is_on(self.hass, dev1.entity_id))
|
||||
self.assertTrue(light.is_on(self.hass, dev2.entity_id))
|
||||
@@ -160,7 +160,7 @@ class TestLight(unittest.TestCase):
|
||||
# toggle all lights
|
||||
light.toggle(self.hass)
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertFalse(light.is_on(self.hass, dev1.entity_id))
|
||||
self.assertFalse(light.is_on(self.hass, dev2.entity_id))
|
||||
@@ -173,7 +173,7 @@ class TestLight(unittest.TestCase):
|
||||
self.hass, dev2.entity_id, rgb_color=(255, 255, 255))
|
||||
light.turn_on(self.hass, dev3.entity_id, xy_color=(.4, .6))
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
method, data = dev1.last_call('turn_on')
|
||||
self.assertEqual(
|
||||
@@ -197,7 +197,7 @@ class TestLight(unittest.TestCase):
|
||||
self.hass, dev2.entity_id,
|
||||
profile=prof_name, brightness=100, xy_color=(.4, .6))
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
method, data = dev1.last_call('turn_on')
|
||||
self.assertEqual(
|
||||
@@ -217,7 +217,7 @@ class TestLight(unittest.TestCase):
|
||||
light.turn_on(self.hass, dev2.entity_id, xy_color=["bla-di-bla", 5])
|
||||
light.turn_on(self.hass, dev3.entity_id, rgb_color=[255, None, 2])
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
method, data = dev1.last_call('turn_on')
|
||||
self.assertEqual({}, data)
|
||||
@@ -233,7 +233,7 @@ class TestLight(unittest.TestCase):
|
||||
self.hass, dev1.entity_id,
|
||||
profile=prof_name, brightness='bright', rgb_color='yellowish')
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
method, data = dev1.last_call('turn_on')
|
||||
self.assertEqual({}, data)
|
||||
@@ -273,7 +273,7 @@ class TestLight(unittest.TestCase):
|
||||
|
||||
light.turn_on(self.hass, dev1.entity_id, profile='test')
|
||||
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
method, data = dev1.last_call('turn_on')
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
@@ -139,7 +139,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
@@ -147,28 +147,28 @@ class TestLightMQTT(unittest.TestCase):
|
||||
self.assertEqual(255, state.attributes.get('brightness'))
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', '0')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb/brightness/status', '100')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(100,
|
||||
light_state.attributes['brightness'])
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', '1')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb/rgb/status',
|
||||
'125,125,125')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.assertEqual([125, 125, 125],
|
||||
@@ -198,26 +198,26 @@ class TestLightMQTT(unittest.TestCase):
|
||||
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
self.assertEqual(255, state.attributes.get('brightness'))
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_scale/status', 'off')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_scale/status', 'on')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_scale/brightness/status', '99')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(255,
|
||||
light_state.attributes['brightness'])
|
||||
|
||||
@@ -249,7 +249,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||
'{"hello": "ON"}')
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb/brightness/status',
|
||||
'{"hello": "50"}')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
@@ -277,7 +277,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
|
||||
light.turn_on(self.hass, 'light.test')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(('test_light_rgb/set', 'on', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
@@ -285,7 +285,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
|
||||
light.turn_off(self.hass, 'light.test')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(('test_light_rgb/set', 'off', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
@@ -294,7 +294,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||
|
||||
light.turn_on(self.hass, 'light.test', rgb_color=[75, 75, 75],
|
||||
brightness=50)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
# Calls are threaded so we need to reorder them
|
||||
bright_call, rgb_call, state_call = \
|
||||
@@ -333,7 +333,7 @@ class TestLightMQTT(unittest.TestCase):
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
|
||||
@@ -78,7 +78,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
self.assertIsNone(state.attributes.get('brightness'))
|
||||
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON"}')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
@@ -112,7 +112,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
'"color":{"r":255,"g":255,"b":255},' +
|
||||
'"brightness":255}'
|
||||
)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
@@ -121,7 +121,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
|
||||
# Turn the light off
|
||||
fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"OFF"}')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
@@ -130,10 +130,10 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
'{"state":"ON",' +
|
||||
'"brightness":100}'
|
||||
)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(100,
|
||||
light_state.attributes['brightness'])
|
||||
|
||||
@@ -141,7 +141,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
'{"state":"ON",' +
|
||||
'"color":{"r":125,"g":125,"b":125}}'
|
||||
)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
light_state = self.hass.states.get('light.test')
|
||||
self.assertEqual([125, 125, 125],
|
||||
@@ -166,7 +166,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
|
||||
light.turn_on(self.hass, 'light.test')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(('test_light_rgb/set', '{"state": "ON"}', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
@@ -174,7 +174,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
|
||||
light.turn_off(self.hass, 'light.test')
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(('test_light_rgb/set', '{"state": "OFF"}', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
@@ -183,7 +183,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
|
||||
light.turn_on(self.hass, 'light.test', rgb_color=[75, 75, 75],
|
||||
brightness=50)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.mock_calls[-1][1][0])
|
||||
@@ -221,7 +221,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
||||
light.turn_on(self.hass, 'light.test', flash="short")
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.mock_calls[-1][1][0])
|
||||
@@ -233,7 +233,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
self.assertEqual("ON", message_json["state"])
|
||||
|
||||
light.turn_on(self.hass, 'light.test', flash="long")
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.mock_calls[-1][1][0])
|
||||
@@ -261,7 +261,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
||||
light.turn_on(self.hass, 'light.test', transition=10)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.mock_calls[-1][1][0])
|
||||
@@ -274,7 +274,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
|
||||
# Transition back off
|
||||
light.turn_off(self.hass, 'light.test', transition=10)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual('test_light_rgb/set',
|
||||
self.mock_publish.mock_calls[-1][1][0])
|
||||
@@ -312,7 +312,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
'"color":{"r":255,"g":255,"b":255},' +
|
||||
'"brightness": 255}'
|
||||
)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('light.test')
|
||||
self.assertEqual(STATE_ON, state.state)
|
||||
@@ -324,7 +324,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
'{"state":"ON",' +
|
||||
'"color":{"r":"bad","g":"val","b":"test"}}'
|
||||
)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
# Color should not have changed
|
||||
state = self.hass.states.get('light.test')
|
||||
@@ -336,7 +336,7 @@ class TestLightMQTTJSON(unittest.TestCase):
|
||||
'{"state":"ON",' +
|
||||
'"brightness": "badValue"}'
|
||||
)
|
||||
self.hass.pool.block_till_done()
|
||||
self.hass.block_till_done()
|
||||
|
||||
# Brightness should not have changed
|
||||
state = self.hass.states.get('light.test')
|
||||
|
||||
Reference in new issue
Block a user