Import shuffle (#27935)

* Simplify persistent_notification ws command

* Move cors import inside setup

* Fix stream imports
pull/27933/head
Paulus Schoutsen 2019-10-19 12:44:51 -07:00 committed by GitHub
parent febc48c84b
commit bb5da77f2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 11 deletions

View File

@ -1,5 +1,4 @@
"""Provide CORS support for the HTTP component."""
import aiohttp_cors
from aiohttp.web_urldispatcher import Resource, ResourceRoute, StaticResource
from aiohttp.hdrs import ACCEPT, CONTENT_TYPE, ORIGIN, AUTHORIZATION
@ -22,6 +21,10 @@ VALID_CORS_TYPES = (Resource, ResourceRoute, StaticResource)
@callback
def setup_cors(app, origins):
"""Set up CORS."""
# This import should remain here. That way the HTTP integration can always
# be imported by other integrations without it's requirements being installed.
import aiohttp_cors
cors = aiohttp_cors.setup(
app,
defaults={

View File

@ -52,11 +52,6 @@ STATE = "notifying"
STATUS_UNREAD = "unread"
STATUS_READ = "read"
WS_TYPE_GET_NOTIFICATIONS = "persistent_notification/get"
SCHEMA_WS_GET = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend(
{vol.Required("type"): WS_TYPE_GET_NOTIFICATIONS}
)
@bind_hass
def create(hass, message, title=None, notification_id=None):
@ -198,14 +193,13 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
DOMAIN, SERVICE_MARK_READ, mark_read_service, SCHEMA_SERVICE_MARK_READ
)
hass.components.websocket_api.async_register_command(
WS_TYPE_GET_NOTIFICATIONS, websocket_get_notifications, SCHEMA_WS_GET
)
hass.components.websocket_api.async_register_command(websocket_get_notifications)
return True
@callback
@websocket_api.websocket_command({vol.Required("type"): "persistent_notification/get"})
def websocket_get_notifications(
hass: HomeAssistant,
connection: websocket_api.ActiveConnection,

View File

@ -22,8 +22,6 @@ from .const import (
)
from .core import PROVIDERS
from .hls import async_setup_hls
from .recorder import async_setup_recorder
from .worker import stream_worker
try:
import uvloop
@ -105,6 +103,9 @@ def request_stream(hass, stream_source, *, fmt="hls", keepalive=False, options=N
async def async_setup(hass, config):
"""Set up stream."""
# Keep import here so that we can import stream integration without installing reqs
from .recorder import async_setup_recorder
hass.data[DOMAIN] = {}
hass.data[DOMAIN][ATTR_ENDPOINTS] = {}
hass.data[DOMAIN][ATTR_STREAMS] = {}
@ -182,6 +183,9 @@ class Stream:
def start(self):
"""Start a stream."""
# Keep import here so that we can import stream integration without installing reqs
from .worker import stream_worker
if self._thread is None or not self._thread.isAlive():
self._thread_quit = threading.Event()
self._thread = threading.Thread(