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

If registration supports encryption then return encrypted payloads (#21853)

This commit is contained in:
Robbie Trencheny
2019-03-11 05:34:58 -07:00
committed by Charles Garwood
parent c401f35a43
commit 785fd273e3
7 changed files with 91 additions and 24 deletions

View File

@@ -3,7 +3,7 @@ from functools import partial
import logging
from typing import Dict
from aiohttp.web import HTTPBadRequest, json_response, Response, Request
from aiohttp.web import HTTPBadRequest, Response, Request
import voluptuous as vol
from homeassistant.components.device_tracker import (DOMAIN as DT_DOMAIN,
@@ -32,7 +32,8 @@ from .const import (ATTR_APP_COMPONENT, DATA_DELETED_IDS,
WEBHOOK_TYPE_UPDATE_REGISTRATION)
from .helpers import (_decrypt_payload, empty_okay_response,
registration_context, safe_registration, savable_state)
registration_context, safe_registration, savable_state,
webhook_response)
_LOGGER = logging.getLogger(__name__)
@@ -127,14 +128,16 @@ async def handle_webhook(store: Store, hass: HomeAssistantType,
try:
tpl = template.Template(data[ATTR_TEMPLATE], hass)
rendered = tpl.async_render(data.get(ATTR_TEMPLATE_VARIABLES))
return json_response({"rendered": rendered}, headers=headers)
return webhook_response({"rendered": rendered},
registration=registration, headers=headers)
# noqa: E722 pylint: disable=broad-except
except (ValueError, TemplateError, Exception) as ex:
_LOGGER.error("Error when rendering template during mobile_app "
"webhook (device name: %s): %s",
registration[ATTR_DEVICE_NAME], ex)
return json_response(({"error": str(ex)}), status=HTTP_BAD_REQUEST,
headers=headers)
return webhook_response(({"error": str(ex)}),
status=HTTP_BAD_REQUEST,
registration=registration, headers=headers)
if webhook_type == WEBHOOK_TYPE_UPDATE_LOCATION:
try:
@@ -159,4 +162,5 @@ async def handle_webhook(store: Store, hass: HomeAssistantType,
_LOGGER.error("Error updating mobile_app registration: %s", ex)
return empty_okay_response()
return json_response(safe_registration(new_registration))
return webhook_response(safe_registration(new_registration),
registration=registration, headers=headers)