From bb5da77f2c6535754d6aeef4c6b21c71784ee7b9 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 19 Oct 2019 12:44:51 -0700 Subject: [PATCH] Import shuffle (#27935) * Simplify persistent_notification ws command * Move cors import inside setup * Fix stream imports --- homeassistant/components/http/cors.py | 5 ++++- .../components/persistent_notification/__init__.py | 10 ++-------- homeassistant/components/stream/__init__.py | 8 ++++++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/http/cors.py b/homeassistant/components/http/cors.py index 0e6b9f9439a..de4547f4782 100644 --- a/homeassistant/components/http/cors.py +++ b/homeassistant/components/http/cors.py @@ -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={ diff --git a/homeassistant/components/persistent_notification/__init__.py b/homeassistant/components/persistent_notification/__init__.py index 6b9c7c44ddf..33f17b18a80 100644 --- a/homeassistant/components/persistent_notification/__init__.py +++ b/homeassistant/components/persistent_notification/__init__.py @@ -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, diff --git a/homeassistant/components/stream/__init__.py b/homeassistant/components/stream/__init__.py index 4c93ce46135..a83f05820e2 100644 --- a/homeassistant/components/stream/__init__.py +++ b/homeassistant/components/stream/__init__.py @@ -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(