Move HomeAssistantView to separate file. Convert http to async syntax. [skip ci] (#12982)
* Move HomeAssistantView to separate file. Convert http to async syntax. * pylint * websocket api * update emulated_hue for async/await * Lint
This commit is contained in:
1 parent
2ee73ca911
commit
321eb2ec6f
17 files changed
+292
-344
No files matched your search
@@ -1,5 +1,5 @@
|
||||
"""Authentication for HTTP component."""
|
||||
import asyncio
|
||||
|
||||
import base64
|
||||
import hmac
|
||||
import logging
|
||||
@@ -20,13 +20,12 @@ _LOGGER = logging.getLogger(__name__)
|
||||
def setup_auth(app, trusted_networks, api_password):
|
||||
"""Create auth middleware for the app."""
|
||||
@middleware
|
||||
@asyncio.coroutine
|
||||
def auth_middleware(request, handler):
|
||||
async def auth_middleware(request, handler):
|
||||
"""Authenticate as middleware."""
|
||||
# If no password set, just always set authenticated=True
|
||||
if api_password is None:
|
||||
request[KEY_AUTHENTICATED] = True
|
||||
return (yield from handler(request))
|
||||
return await handler(request)
|
||||
|
||||
# Check authentication
|
||||
authenticated = False
|
||||
@@ -50,10 +49,9 @@ def setup_auth(app, trusted_networks, api_password):
|
||||
authenticated = True
|
||||
|
||||
request[KEY_AUTHENTICATED] = authenticated
|
||||
return (yield from handler(request))
|
||||
return await handler(request)
|
||||
|
||||
@asyncio.coroutine
|
||||
def auth_startup(app):
|
||||
async def auth_startup(app):
|
||||
"""Initialize auth middleware when app starts up."""
|
||||
app.middlewares.append(auth_middleware)
|
||||
|
||||
|
||||
Reference in new issue
Block a user