diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index 30dfa6b6db0..e5305245b18 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -14,6 +14,7 @@ from homeassistant.const import ( __version__, EVENT_HOMEASSISTANT_START, REQUIRED_PYTHON_VER, + REQUIRED_PYTHON_VER_WIN, RESTART_EXIT_CODE, ) from homeassistant.util.async import run_callback_threadsafe @@ -64,7 +65,12 @@ def monkey_patch_asyncio(): def validate_python() -> None: """Validate we're running the right Python version.""" - if sys.version_info[:3] < REQUIRED_PYTHON_VER: + if sys.platform == "win32" and \ + sys.version_info[:3] < REQUIRED_PYTHON_VER_WIN: + print("Home Assistant requires at least Python {}.{}.{}".format( + *REQUIRED_PYTHON_VER_WIN)) + sys.exit(1) + elif sys.version_info[:3] < REQUIRED_PYTHON_VER: print("Home Assistant requires at least Python {}.{}.{}".format( *REQUIRED_PYTHON_VER)) sys.exit(1) diff --git a/homeassistant/const.py b/homeassistant/const.py index fcba511fe10..abe932fad15 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -6,6 +6,7 @@ PATCH_VERSION = '0.dev0' __short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION) __version__ = '{}.{}'.format(__short_version__, PATCH_VERSION) REQUIRED_PYTHON_VER = (3, 4, 2) +REQUIRED_PYTHON_VER_WIN = (3, 5, 2) PROJECT_NAME = 'Home Assistant' PROJECT_PACKAGE_NAME = 'homeassistant' diff --git a/homeassistant/core.py b/homeassistant/core.py index 5fb7d2761cc..8de1e2b2535 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -107,7 +107,11 @@ class HomeAssistant(object): def __init__(self, loop=None): """Initialize new Home Assistant object.""" - self.loop = loop or asyncio.get_event_loop() + if sys.platform == "win32": + self.loop = loop or asyncio.ProactorEventLoop() + else: + self.loop = loop or asyncio.get_event_loop() + self.executor = ThreadPoolExecutor(max_workers=5) self.loop.set_default_executor(self.executor) self.loop.set_exception_handler(self._async_exception_handler) diff --git a/tests/common.py b/tests/common.py index af65a93f216..ee84cc7c642 100644 --- a/tests/common.py +++ b/tests/common.py @@ -1,6 +1,7 @@ """Test the helper method for writing tests.""" import asyncio import os +import sys from datetime import timedelta from unittest import mock from unittest.mock import patch @@ -33,7 +34,10 @@ def get_test_config_dir(*add_path): def get_test_home_assistant(): """Return a Home Assistant object pointing at test config dir.""" - loop = asyncio.new_event_loop() + if sys.platform == "win32": + loop = asyncio.ProactorEventLoop() + else: + loop = asyncio.new_event_loop() hass = loop.run_until_complete(async_test_home_assistant(loop)) hass.allow_pool = True