RFC: Call services directly (#18720)

* Call services directly

* Simplify

* Type

* Lint

* Update name

* Fix tests

* Catch exceptions in HTTP view

* Lint

* Handle ServiceNotFound in API endpoints that call services

* Type

* Don't crash recorder on non-JSON serializable objects
This commit is contained in:
Paulus Schoutsen authored and Pascal Vizeli committed 2018-11-30 21:28:35 +01:00
1 parent 53cbb28926
commit df21dd21f2
30 files changed
+312 -186

No files matched your search

+7 -1
View File
@@ -9,7 +9,9 @@ import json
import logging
from aiohttp import web
from aiohttp.web_exceptions import HTTPUnauthorized, HTTPInternalServerError
from aiohttp.web_exceptions import (
HTTPUnauthorized, HTTPInternalServerError, HTTPBadRequest)
import voluptuous as vol
from homeassistant.components.http.ban import process_success_login
from homeassistant.core import Context, is_callback
@@ -114,6 +116,10 @@ def request_handler_factory(view, handler):
if asyncio.iscoroutine(result):
result = await result
except vol.Invalid:
raise HTTPBadRequest()
except exceptions.ServiceNotFound:
raise HTTPInternalServerError()
except exceptions.Unauthorized:
raise HTTPUnauthorized()