Convert more files to async/await syntax (#14142)

* Move more files to async/await syntax

* Attempt Work around pylint bug

Using lazytox :P
This commit is contained in:
Otto Winter authored and Paulus Schoutsen committed 2018-04-28 19:26:20 -04:00
1 parent a0b14c2913
commit a4bf421044
27 files changed
+229 -327

No files matched your search

@@ -70,8 +70,7 @@ def request_sync(hass):
hass.services.call(DOMAIN, SERVICE_REQUEST_SYNC)
@asyncio.coroutine
def async_setup(hass: HomeAssistant, yaml_config: Dict[str, Any]):
async def async_setup(hass: HomeAssistant, yaml_config: Dict[str, Any]):
"""Activate Google Actions component."""
config = yaml_config.get(DOMAIN, {})
agent_user_id = config.get(CONF_AGENT_USER_ID)
@@ -79,20 +78,19 @@ def async_setup(hass: HomeAssistant, yaml_config: Dict[str, Any]):
hass.http.register_view(GoogleAssistantAuthView(hass, config))
async_register_http(hass, config)
@asyncio.coroutine
def request_sync_service_handler(call):
async def request_sync_service_handler(call):
"""Handle request sync service calls."""
websession = async_get_clientsession(hass)
try:
with async_timeout.timeout(5, loop=hass.loop):
res = yield from websession.post(
res = await websession.post(
REQUEST_SYNC_BASE_URL,
params={'key': api_key},
json={'agent_user_id': agent_user_id})
_LOGGER.info("Submitted request_sync request to Google")
res.raise_for_status()
except aiohttp.ClientResponseError:
body = yield from res.read()
body = await res.read()
_LOGGER.error(
'request_sync request failed: %d %s', res.status, body)
except (asyncio.TimeoutError, aiohttp.ClientError):
@@ -1,6 +1,5 @@
"""Google Assistant OAuth View."""
import asyncio
import logging
# Typing imports
@@ -44,8 +43,7 @@ class GoogleAssistantAuthView(HomeAssistantView):
self.client_id = cfg.get(CONF_CLIENT_ID)
self.access_token = cfg.get(CONF_ACCESS_TOKEN)
@asyncio.coroutine
def get(self, request: Request) -> Response:
async def get(self, request: Request) -> Response:
"""Handle oauth token request."""
query = request.query
redirect_uri = query.get('redirect_uri')
@@ -4,7 +4,6 @@ Support for Google Actions Smart Home Control.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/google_assistant/
"""
import asyncio
import logging
from aiohttp.hdrs import AUTHORIZATION
@@ -77,14 +76,13 @@ class GoogleAssistantView(HomeAssistantView):
self.access_token = access_token
self.gass_config = gass_config
@asyncio.coroutine
def post(self, request: Request) -> Response:
async def post(self, request: Request) -> Response:
"""Handle Google Assistant requests."""
auth = request.headers.get(AUTHORIZATION, None)
if 'Bearer {}'.format(self.access_token) != auth:
return self.json_message("missing authorization", status_code=401)
message = yield from request.json() # type: dict
result = yield from async_handle_message(
message = await request.json() # type: dict
result = await async_handle_message(
request.app['hass'], self.gass_config, message)
return self.json(result)