Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -12,15 +12,15 @@ from homeassistant.components.http.view import HomeAssistantView
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = 'webhook'
|
||||
DOMAIN = "webhook"
|
||||
|
||||
URL_WEBHOOK_PATH = "/api/webhook/{webhook_id}"
|
||||
|
||||
WS_TYPE_LIST = 'webhook/list'
|
||||
WS_TYPE_LIST = "webhook/list"
|
||||
|
||||
SCHEMA_WS_LIST = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
||||
vol.Required('type'): WS_TYPE_LIST,
|
||||
})
|
||||
SCHEMA_WS_LIST = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
|
||||
{vol.Required("type"): WS_TYPE_LIST}
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
@@ -30,13 +30,9 @@ def async_register(hass, domain, name, webhook_id, handler):
|
||||
handlers = hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
if webhook_id in handlers:
|
||||
raise ValueError('Handler is already defined!')
|
||||
raise ValueError("Handler is already defined!")
|
||||
|
||||
handlers[webhook_id] = {
|
||||
'domain': domain,
|
||||
'name': name,
|
||||
'handler': handler
|
||||
}
|
||||
handlers[webhook_id] = {"domain": domain, "name": name, "handler": handler}
|
||||
|
||||
|
||||
@callback
|
||||
@@ -57,8 +53,7 @@ def async_generate_id():
|
||||
@bind_hass
|
||||
def async_generate_url(hass, webhook_id):
|
||||
"""Generate the full URL for a webhook_id."""
|
||||
return "{}{}".format(hass.config.api.base_url,
|
||||
async_generate_path(webhook_id))
|
||||
return "{}{}".format(hass.config.api.base_url, async_generate_path(webhook_id))
|
||||
|
||||
|
||||
@callback
|
||||
@@ -75,12 +70,11 @@ async def async_handle_webhook(hass, webhook_id, request):
|
||||
|
||||
# Always respond successfully to not give away if a hook exists or not.
|
||||
if webhook is None:
|
||||
_LOGGER.warning(
|
||||
'Received message for unregistered webhook %s', webhook_id)
|
||||
_LOGGER.warning("Received message for unregistered webhook %s", webhook_id)
|
||||
return Response(status=200)
|
||||
|
||||
try:
|
||||
response = await webhook['handler'](hass, webhook_id, request)
|
||||
response = await webhook["handler"](hass, webhook_id, request)
|
||||
if response is None:
|
||||
response = Response(status=200)
|
||||
return response
|
||||
@@ -93,8 +87,7 @@ async def async_setup(hass, config):
|
||||
"""Initialize the webhook component."""
|
||||
hass.http.register_view(WebhookView)
|
||||
hass.components.websocket_api.async_register_command(
|
||||
WS_TYPE_LIST, websocket_list,
|
||||
SCHEMA_WS_LIST
|
||||
WS_TYPE_LIST, websocket_list, SCHEMA_WS_LIST
|
||||
)
|
||||
return True
|
||||
|
||||
@@ -108,7 +101,7 @@ class WebhookView(HomeAssistantView):
|
||||
|
||||
async def post(self, request, webhook_id):
|
||||
"""Handle webhook call."""
|
||||
hass = request.app['hass']
|
||||
hass = request.app["hass"]
|
||||
return await async_handle_webhook(hass, webhook_id, request)
|
||||
|
||||
|
||||
@@ -116,11 +109,9 @@ class WebhookView(HomeAssistantView):
|
||||
def websocket_list(hass, connection, msg):
|
||||
"""Return a list of webhooks."""
|
||||
handlers = hass.data.setdefault(DOMAIN, {})
|
||||
result = [{
|
||||
'webhook_id': webhook_id,
|
||||
'domain': info['domain'],
|
||||
'name': info['name'],
|
||||
} for webhook_id, info in handlers.items()]
|
||||
result = [
|
||||
{"webhook_id": webhook_id, "domain": info["domain"], "name": info["name"]}
|
||||
for webhook_id, info in handlers.items()
|
||||
]
|
||||
|
||||
connection.send_message(
|
||||
websocket_api.result_message(msg['id'], result))
|
||||
connection.send_message(websocket_api.result_message(msg["id"], result))
|
||||
Reference in new issue
Block a user