Fix cloud webhook body (#20739)

* Bugfix cloud webhooks text response

* address comments

* Fix lint
This commit is contained in:
Pascal Vizeli authored and Paulus Schoutsen committed 2019-02-04 22:01:49 -08:00
1 parent 94ab5dca7f
commit cfa03a408e
5 files changed
+40 -35

No files matched your search

+3 -4
View File
@@ -12,9 +12,10 @@ from homeassistant.components.alexa import smart_home as alexa
from homeassistant.components.google_assistant import smart_home as ga
from homeassistant.core import callback
from homeassistant.util.decorator import Registry
from homeassistant.util.aiohttp import MockRequest, serialize_response
from homeassistant.util.aiohttp import MockRequest
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from . import auth_api
from . import utils
from .const import MESSAGE_EXPIRATION, MESSAGE_AUTH_FAIL
HANDLERS = Registry()
@@ -360,10 +361,8 @@ async def async_handle_webhook(hass, cloud, payload):
response = await hass.components.webhook.async_handle_webhook(
found['webhook_id'], request)
response_dict = serialize_response(response)
response_dict = utils.aiohttp_serialize_response(response)
body = response_dict.get('body')
if body:
body = body.decode('utf-8')
return {
'body': body,
+13
View File
@@ -0,0 +1,13 @@
"""Helper functions for cloud components."""
from typing import Any, Dict
from aiohttp import web
def aiohttp_serialize_response(response: web.Response) -> Dict[str, Any]:
"""Serialize an aiohttp response to a dictionary."""
return {
'status': response.status,
'body': response.text,
'headers': dict(response.headers),
}