Context (#15674)
* Add context * Add context to switch/light services * Test set_state API * Lint * Fix tests * Do not include context yet in comparison * Do not pass in loop * Fix Z-Wave tests * Add websocket test without user
This commit is contained in:
1 parent
867f80715e
commit
c7f4bdafc0
16 files changed
+363
-109
No files matched your search
@@ -13,7 +13,7 @@ from aiohttp.web_exceptions import HTTPUnauthorized, HTTPInternalServerError
|
||||
|
||||
import homeassistant.remote as rem
|
||||
from homeassistant.components.http.ban import process_success_login
|
||||
from homeassistant.core import is_callback
|
||||
from homeassistant.core import Context, is_callback
|
||||
from homeassistant.const import CONTENT_TYPE_JSON
|
||||
|
||||
from .const import KEY_AUTHENTICATED, KEY_REAL_IP
|
||||
@@ -32,6 +32,14 @@ class HomeAssistantView:
|
||||
cors_allowed = False
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def context(self, request):
|
||||
"""Generate a context from a request."""
|
||||
user = request.get('hass_user')
|
||||
if user is None:
|
||||
return Context()
|
||||
|
||||
return Context(user_id=user.id)
|
||||
|
||||
def json(self, result, status_code=200, headers=None):
|
||||
"""Return a JSON response."""
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user