1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

async HTTP component (#3914)

* Migrate WSGI to asyncio

* Rename wsgi -> http

* Python 3.4 compat

* Move linting to Python 3.4

* lint

* Lint

* Fix Python 3.4 mock_open + binary data

* Surpress logging aiohttp.access

* Spelling

* Sending files is a coroutine

* More callback annotations and naming fixes

* Fix ios
This commit is contained in:
Paulus Schoutsen
2016-10-23 23:48:01 -07:00
committed by GitHub
parent 9aa88819a5
commit 519d9f2fd0
45 changed files with 1422 additions and 1009 deletions

View File

@@ -38,23 +38,11 @@ def get_test_home_assistant(num_threads=None):
orig_num_threads = ha.MIN_WORKER_THREAD
ha.MIN_WORKER_THREAD = num_threads
hass = ha.HomeAssistant(loop)
hass = loop.run_until_complete(async_test_home_assistant(loop))
if num_threads:
ha.MIN_WORKER_THREAD = orig_num_threads
hass.config.location_name = 'test home'
hass.config.config_dir = get_test_config_dir()
hass.config.latitude = 32.87336
hass.config.longitude = -117.22743
hass.config.elevation = 0
hass.config.time_zone = date_util.get_time_zone('US/Pacific')
hass.config.units = METRIC_SYSTEM
hass.config.skip_pip = True
if 'custom_components.test' not in loader.AVAILABLE_COMPONENTS:
loader.prepare(hass)
# FIXME should not be a daemon. Means hass.stop() not called in teardown
stop_event = threading.Event()
@@ -98,6 +86,35 @@ def get_test_home_assistant(num_threads=None):
return hass
@asyncio.coroutine
def async_test_home_assistant(loop):
"""Return a Home Assistant object pointing at test config dir."""
loop._thread_ident = threading.get_ident()
def get_hass():
"""Temp while we migrate core HASS over to be async constructors."""
hass = ha.HomeAssistant(loop)
hass.config.location_name = 'test home'
hass.config.config_dir = get_test_config_dir()
hass.config.latitude = 32.87336
hass.config.longitude = -117.22743
hass.config.elevation = 0
hass.config.time_zone = date_util.get_time_zone('US/Pacific')
hass.config.units = METRIC_SYSTEM
hass.config.skip_pip = True
if 'custom_components.test' not in loader.AVAILABLE_COMPONENTS:
loader.prepare(hass)
hass.state = ha.CoreState.running
return hass
hass = yield from loop.run_in_executor(None, get_hass)
return hass
def get_test_instance_port():
"""Return unused port for running test instance.
@@ -181,8 +198,19 @@ def mock_state_change_event(hass, new_state, old_state=None):
def mock_http_component(hass):
"""Mock the HTTP component."""
hass.wsgi = mock.MagicMock()
hass.http = mock.MagicMock()
hass.config.components.append('http')
hass.http.views = {}
def mock_register_view(view):
"""Store registered view."""
if isinstance(view, type):
# Instantiate the view, if needed
view = view(hass)
hass.http.views[view.name] = view
hass.http.register_view = mock_register_view
def mock_mqtt_component(hass):