Skip to content

Commit

Permalink
Hello Python 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Feb 22, 2018
1 parent 6b03cb9 commit 7d2717d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 39 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ addons:
matrix:
fast_finish: true
include:
- python: "3.4.2"
- python: "3.5.3"
env: TOXENV=lint
- python: "3.4.2"
- python: "3.5.3"
env: TOXENV=pylint
- python: "3.4.2"
env: TOXENV=py34
# - python: "3.5"
# env: TOXENV=typing
- python: "3.5.3"
Expand Down
8 changes: 1 addition & 7 deletions homeassistant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
__version__,
EVENT_HOMEASSISTANT_START,
REQUIRED_PYTHON_VER,
REQUIRED_PYTHON_VER_WIN,
RESTART_EXIT_CODE,
)

Expand All @@ -33,12 +32,7 @@ def attempt_use_uvloop():

def validate_python() -> None:
"""Validate that the right Python version is running."""
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:
if sys.version_info[:3] < REQUIRED_PYTHON_VER:
print("Home Assistant requires at least Python {}.{}.{}".format(
*REQUIRED_PYTHON_VER))
sys.exit(1)
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,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)
REQUIRED_PYTHON_VER = (3, 5, 3)

# Format for platforms
PLATFORM_FORMAT = '{}.{}'
Expand Down
36 changes: 16 additions & 20 deletions homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ def start(self) -> None:
finally:
self.loop.close()

@asyncio.coroutine
def async_start(self):
async def async_start(self):
"""Finalize startup from inside the event loop.
This method is a coroutine.
Expand All @@ -181,7 +180,7 @@ def async_start(self):
# Only block for EVENT_HOMEASSISTANT_START listener
self.async_stop_track_tasks()
with timeout(TIMEOUT_EVENT_START, loop=self.loop):
yield from self.async_block_till_done()
await self.async_block_till_done()
except asyncio.TimeoutError:
_LOGGER.warning(
'Something is blocking Home Assistant from wrapping up the '
Expand All @@ -190,7 +189,7 @@ def async_start(self):
', '.join(self.config.components))

# Allow automations to set up the start triggers before changing state
yield from asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0, loop=self.loop)
self.state = CoreState.running
_async_create_timer(self)

Expand Down Expand Up @@ -259,27 +258,25 @@ def block_till_done(self) -> None:
run_coroutine_threadsafe(
self.async_block_till_done(), loop=self.loop).result()

@asyncio.coroutine
def async_block_till_done(self):
async def async_block_till_done(self):
"""Block till all pending work is done."""
# To flush out any call_soon_threadsafe
yield from asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0, loop=self.loop)

while self._pending_tasks:
pending = [task for task in self._pending_tasks
if not task.done()]
self._pending_tasks.clear()
if pending:
yield from asyncio.wait(pending, loop=self.loop)
await asyncio.wait(pending, loop=self.loop)
else:
yield from asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0, loop=self.loop)

def stop(self) -> None:
"""Stop Home Assistant and shuts down all threads."""
fire_coroutine_threadsafe(self.async_stop(), self.loop)

@asyncio.coroutine
def async_stop(self, exit_code=0) -> None:
async def async_stop(self, exit_code=0) -> None:
"""Stop Home Assistant and shuts down all threads.
This method is a coroutine.
Expand All @@ -288,12 +285,12 @@ def async_stop(self, exit_code=0) -> None:
self.state = CoreState.stopping
self.async_track_tasks()
self.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
yield from self.async_block_till_done()
await self.async_block_till_done()

# stage 2
self.state = CoreState.not_running
self.bus.async_fire(EVENT_HOMEASSISTANT_CLOSE)
yield from self.async_block_till_done()
await self.async_block_till_done()
self.executor.shutdown()

self.exit_code = exit_code
Expand Down Expand Up @@ -912,8 +909,8 @@ def call(self, domain, service, service_data=None, blocking=False):
self._hass.loop
).result()

@asyncio.coroutine
def async_call(self, domain, service, service_data=None, blocking=False):
async def async_call(self, domain, service, service_data=None,
blocking=False):
"""
Call a service.
Expand Down Expand Up @@ -956,14 +953,13 @@ def service_executed(event):
self._hass.bus.async_fire(EVENT_CALL_SERVICE, event_data)

if blocking:
done, _ = yield from asyncio.wait(
done, _ = await asyncio.wait(
[fut], loop=self._hass.loop, timeout=SERVICE_CALL_LIMIT)
success = bool(done)
unsub()
return success

@asyncio.coroutine
def _event_to_service_call(self, event):
async def _event_to_service_call(self, event):
"""Handle the SERVICE_CALLED events from the EventBus."""
service_data = event.data.get(ATTR_SERVICE_DATA) or {}
domain = event.data.get(ATTR_DOMAIN).lower()
Expand Down Expand Up @@ -1007,15 +1003,15 @@ def fire_service_executed():
service_handler.func(service_call)
fire_service_executed()
elif service_handler.is_coroutinefunction:
yield from service_handler.func(service_call)
await service_handler.func(service_call)
fire_service_executed()
else:
def execute_service():
"""Execute a service and fires a SERVICE_EXECUTED event."""
service_handler.func(service_call)
fire_service_executed()

yield from self._hass.async_add_job(execute_service)
await self._hass.async_add_job(execute_service)
except Exception: # pylint: disable=broad-except
_LOGGER.exception('Error executing service %s', service_call)

Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3
"""Home Assistant setup script."""
import sys

from setuptools import setup, find_packages

import homeassistant.const as hass_const
Expand All @@ -27,7 +25,6 @@
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Home Automation'
Expand Down Expand Up @@ -64,9 +61,7 @@

MIN_PY_VERSION = '.'.join(map(
str,
hass_const.REQUIRED_PYTHON_VER_WIN
if sys.platform.startswith('win')
else hass_const.REQUIRED_PYTHON_VER))
hass_const.REQUIRED_PYTHON_VER))

setup(
name=PROJECT_PACKAGE_NAME,
Expand Down

0 comments on commit 7d2717d

Please sign in to comment.