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:
Paulus Schoutsen 2016-09-12 19:16:14 -07:00 committed by Ben Bangert
parent 24f1bff7f1
commit 609d7ebea5
98 changed files with 1680 additions and 1109 deletions

View file

@ -121,7 +121,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
def test_set_target_temp(self):
"""Test the setting of the target temperature."""
climate.set_temperature(self.hass, 30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
state = self.hass.states.get(ENTITY)
self.assertEqual(30.0, state.attributes.get('temperature'))
@ -132,7 +132,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
unit = state.attributes.get('unit_of_measurement')
self._setup_sensor(22.0, unit='bad_unit')
self.hass.pool.block_till_done()
self.hass.block_till_done()
state = self.hass.states.get(ENTITY)
self.assertEqual(unit, state.attributes.get('unit_of_measurement'))
@ -145,7 +145,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
unit = state.attributes.get('unit_of_measurement')
self._setup_sensor(None)
self.hass.pool.block_till_done()
self.hass.block_till_done()
state = self.hass.states.get(ENTITY)
self.assertEqual(unit, state.attributes.get('unit_of_measurement'))
@ -155,9 +155,9 @@ class TestClimateGenericThermostat(unittest.TestCase):
"""Test if target temperature turn heater on."""
self._setup_switch(False)
self._setup_sensor(25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
climate.set_temperature(self.hass, 30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -168,9 +168,9 @@ class TestClimateGenericThermostat(unittest.TestCase):
"""Test if target temperature turn heater off."""
self._setup_switch(True)
self._setup_sensor(30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
climate.set_temperature(self.hass, 25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -181,9 +181,9 @@ class TestClimateGenericThermostat(unittest.TestCase):
"""Test if temperature change turn heater on."""
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -194,9 +194,9 @@ class TestClimateGenericThermostat(unittest.TestCase):
"""Test if temperature change turn heater off."""
self._setup_switch(True)
climate.set_temperature(self.hass, 25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -245,9 +245,9 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
"""Test if target temperature turn ac off."""
self._setup_switch(True)
self._setup_sensor(25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
climate.set_temperature(self.hass, 30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -258,9 +258,9 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
"""Test if target temperature turn ac on."""
self._setup_switch(False)
self._setup_sensor(30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
climate.set_temperature(self.hass, 25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -271,9 +271,9 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
"""Test if temperature change turn ac off."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -284,9 +284,9 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
"""Test if temperature change turn ac on."""
self._setup_switch(False)
climate.set_temperature(self.hass, 25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -336,9 +336,9 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
"""Test if temperature change turn ac on."""
self._setup_switch(False)
climate.set_temperature(self.hass, 25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
def test_temp_change_ac_trigger_on_long_enough(self):
@ -349,9 +349,9 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
return_value=fake_changed):
self._setup_switch(False)
climate.set_temperature(self.hass, 25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -362,9 +362,9 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
"""Test if temperature change turn ac on."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
def test_temp_change_ac_trigger_off_long_enough(self):
@ -375,9 +375,9 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
return_value=fake_changed):
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -426,18 +426,18 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
"""Test if temp change doesn't turn heater off because of time."""
self._setup_switch(True)
climate.set_temperature(self.hass, 25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
def test_temp_change_heater_trigger_on_not_long_enough(self):
"""Test if temp change doesn't turn heater on because of time."""
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
def test_temp_change_heater_trigger_on_long_enough(self):
@ -448,9 +448,9 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
return_value=fake_changed):
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)
@ -465,9 +465,9 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
return_value=fake_changed):
self._setup_switch(True)
climate.set_temperature(self.hass, 25)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.pool.block_till_done()
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
self.assertEqual('switch', call.domain)