move imports in stream component (#27647)

pull/27672/head
Michał Mrozek 2019-10-14 23:20:18 +02:00 committed by Paulus Schoutsen
parent 4efa2f3244
commit 9aa28dfd54
9 changed files with 45 additions and 42 deletions

View File

@ -4,31 +4,32 @@ import threading
import voluptuous as vol
from homeassistant.auth.util import generate_secret
from homeassistant.const import CONF_FILENAME, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import callback
from homeassistant.exceptions import HomeAssistantError
import homeassistant.helpers.config_validation as cv
from homeassistant.loader import bind_hass
from .const import (
ATTR_ENDPOINTS,
ATTR_STREAMS,
CONF_DURATION,
CONF_LOOKBACK,
CONF_STREAM_SOURCE,
DOMAIN,
SERVICE_RECORD,
)
from .core import PROVIDERS
from .hls import async_setup_hls
from .recorder import async_setup_recorder
from .worker import stream_worker
try:
import uvloop
except ImportError:
uvloop = None
from homeassistant.auth.util import generate_secret
import homeassistant.helpers.config_validation as cv
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, CONF_FILENAME
from homeassistant.core import callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.loader import bind_hass
from .const import (
DOMAIN,
ATTR_STREAMS,
ATTR_ENDPOINTS,
CONF_STREAM_SOURCE,
CONF_DURATION,
CONF_LOOKBACK,
SERVICE_RECORD,
)
from .core import PROVIDERS
from .worker import stream_worker
from .hls import async_setup_hls
from .recorder import async_setup_recorder
_LOGGER = logging.getLogger(__name__)

View File

@ -2,17 +2,17 @@
import asyncio
from collections import deque
import io
from typing import List, Any
from typing import Any, List
import attr
from aiohttp import web
import attr
from homeassistant.core import callback
from homeassistant.components.http import HomeAssistantView
from homeassistant.core import callback
from homeassistant.helpers.event import async_call_later
from homeassistant.util.decorator import Registry
from .const import DOMAIN, ATTR_STREAMS
from .const import ATTR_STREAMS, DOMAIN
PROVIDERS = Registry()

View File

@ -5,7 +5,7 @@ from homeassistant.core import callback
from homeassistant.util.dt import utcnow
from .const import FORMAT_CONTENT_TYPE
from .core import StreamView, StreamOutput, PROVIDERS
from .core import PROVIDERS, StreamOutput, StreamView
@callback

View File

@ -1,10 +1,13 @@
"""Provide functionality to record stream."""
import threading
from typing import List
import av
from homeassistant.core import callback
from .core import Segment, StreamOutput, PROVIDERS
from .core import PROVIDERS, Segment, StreamOutput
@callback
@ -14,8 +17,6 @@ def async_setup_recorder(hass):
def recorder_save_worker(file_out: str, segments: List[Segment]):
"""Handle saving stream."""
import av
output = av.open(file_out, "w", options={"movflags": "frag_keyframe"})
output_v = None

View File

@ -3,6 +3,8 @@ from fractions import Fraction
import io
import logging
import av
from .const import AUDIO_SAMPLE_RATE
from .core import Segment, StreamBuffer
@ -11,9 +13,8 @@ _LOGGER = logging.getLogger(__name__)
def generate_audio_frame():
"""Generate a blank audio frame."""
from av import AudioFrame
audio_frame = AudioFrame(format="dbl", layout="mono", samples=1024)
audio_frame = av.AudioFrame(format="dbl", layout="mono", samples=1024)
# audio_bytes = b''.join(b'\x00\x00\x00\x00\x00\x00\x00\x00'
# for i in range(0, 1024))
audio_bytes = b"\x00\x00\x00\x00\x00\x00\x00\x00" * 1024
@ -25,7 +26,6 @@ def generate_audio_frame():
def create_stream_buffer(stream_output, video_stream, audio_frame):
"""Create a new StreamBuffer."""
import av
a_packet = None
segment = io.BytesIO()
@ -45,7 +45,6 @@ def create_stream_buffer(stream_output, video_stream, audio_frame):
def stream_worker(hass, stream, quit_event):
"""Handle consuming streams."""
import av
container = av.open(stream.source, options=stream.options)
try:

View File

@ -1,8 +1,11 @@
"""Collection of test helpers."""
import io
import av
import numpy as np
from homeassistant.components.stream import Stream
from homeassistant.components.stream.const import DOMAIN, ATTR_STREAMS
from homeassistant.components.stream.const import ATTR_STREAMS, DOMAIN
def generate_h264_video():
@ -11,8 +14,6 @@ def generate_h264_video():
See: http://docs.mikeboers.com/pyav/develop/cookbook/numpy.html
"""
import numpy as np
import av
duration = 5
fps = 24

View File

@ -4,8 +4,8 @@ from urllib.parse import urlparse
import pytest
from homeassistant.setup import async_setup_component
from homeassistant.components.stream import request_stream
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from tests.common import async_fire_time_changed

View File

@ -1,16 +1,16 @@
"""The tests for stream."""
from unittest.mock import patch, MagicMock
from unittest.mock import MagicMock, patch
import pytest
from homeassistant.const import CONF_FILENAME
from homeassistant.components.stream.const import (
ATTR_STREAMS,
CONF_LOOKBACK,
CONF_STREAM_SOURCE,
DOMAIN,
SERVICE_RECORD,
CONF_STREAM_SOURCE,
CONF_LOOKBACK,
ATTR_STREAMS,
)
from homeassistant.const import CONF_FILENAME
from homeassistant.exceptions import HomeAssistantError
from homeassistant.setup import async_setup_component

View File

@ -2,11 +2,12 @@
from datetime import timedelta
from io import BytesIO
from unittest.mock import patch
import pytest
from homeassistant.setup import async_setup_component
from homeassistant.components.stream.core import Segment
from homeassistant.components.stream.recorder import recorder_save_worker
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from tests.common import async_fire_time_changed