mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Import shuffle (#27935)
* Simplify persistent_notification ws command * Move cors import inside setup * Fix stream imports
This commit is contained in:
parent
febc48c84b
commit
bb5da77f2c
@ -1,5 +1,4 @@
|
|||||||
"""Provide CORS support for the HTTP component."""
|
"""Provide CORS support for the HTTP component."""
|
||||||
import aiohttp_cors
|
|
||||||
from aiohttp.web_urldispatcher import Resource, ResourceRoute, StaticResource
|
from aiohttp.web_urldispatcher import Resource, ResourceRoute, StaticResource
|
||||||
from aiohttp.hdrs import ACCEPT, CONTENT_TYPE, ORIGIN, AUTHORIZATION
|
from aiohttp.hdrs import ACCEPT, CONTENT_TYPE, ORIGIN, AUTHORIZATION
|
||||||
|
|
||||||
@ -22,6 +21,10 @@ VALID_CORS_TYPES = (Resource, ResourceRoute, StaticResource)
|
|||||||
@callback
|
@callback
|
||||||
def setup_cors(app, origins):
|
def setup_cors(app, origins):
|
||||||
"""Set up CORS."""
|
"""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(
|
cors = aiohttp_cors.setup(
|
||||||
app,
|
app,
|
||||||
defaults={
|
defaults={
|
||||||
|
@ -52,11 +52,6 @@ STATE = "notifying"
|
|||||||
STATUS_UNREAD = "unread"
|
STATUS_UNREAD = "unread"
|
||||||
STATUS_READ = "read"
|
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
|
@bind_hass
|
||||||
def create(hass, message, title=None, notification_id=None):
|
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
|
DOMAIN, SERVICE_MARK_READ, mark_read_service, SCHEMA_SERVICE_MARK_READ
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.components.websocket_api.async_register_command(
|
hass.components.websocket_api.async_register_command(websocket_get_notifications)
|
||||||
WS_TYPE_GET_NOTIFICATIONS, websocket_get_notifications, SCHEMA_WS_GET
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@websocket_api.websocket_command({vol.Required("type"): "persistent_notification/get"})
|
||||||
def websocket_get_notifications(
|
def websocket_get_notifications(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
connection: websocket_api.ActiveConnection,
|
connection: websocket_api.ActiveConnection,
|
||||||
|
@ -22,8 +22,6 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .core import PROVIDERS
|
from .core import PROVIDERS
|
||||||
from .hls import async_setup_hls
|
from .hls import async_setup_hls
|
||||||
from .recorder import async_setup_recorder
|
|
||||||
from .worker import stream_worker
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import uvloop
|
import uvloop
|
||||||
@ -105,6 +103,9 @@ def request_stream(hass, stream_source, *, fmt="hls", keepalive=False, options=N
|
|||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up stream."""
|
"""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] = {}
|
||||||
hass.data[DOMAIN][ATTR_ENDPOINTS] = {}
|
hass.data[DOMAIN][ATTR_ENDPOINTS] = {}
|
||||||
hass.data[DOMAIN][ATTR_STREAMS] = {}
|
hass.data[DOMAIN][ATTR_STREAMS] = {}
|
||||||
@ -182,6 +183,9 @@ class Stream:
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start a stream."""
|
"""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():
|
if self._thread is None or not self._thread.isAlive():
|
||||||
self._thread_quit = threading.Event()
|
self._thread_quit = threading.Event()
|
||||||
self._thread = threading.Thread(
|
self._thread = threading.Thread(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user