Remove FFmpeg input tests (#18131)
* Remove FFmpeg input tests * Not needed here * Removing tests for removed functionality * Minor lint * Fix tests to reflect removed config option * Remove async service registration by request * More lint * Unused imports * Make it a non-breaking change * Update ffmpeg.pypull/18144/head
parent
73ed2ab164
commit
255607f3a5
|
@ -49,10 +49,6 @@ async def async_setup_platform(hass, config, async_add_entities,
|
|||
discovery_info=None):
|
||||
"""Set up the FFmpeg binary motion sensor."""
|
||||
manager = hass.data[DATA_FFMPEG]
|
||||
|
||||
if not await manager.async_run_test(config.get(CONF_INPUT)):
|
||||
return
|
||||
|
||||
entity = FFmpegMotion(hass, manager, config)
|
||||
async_add_entities([entity])
|
||||
|
||||
|
|
|
@ -46,10 +46,6 @@ async def async_setup_platform(hass, config, async_add_entities,
|
|||
discovery_info=None):
|
||||
"""Set up the FFmpeg noise binary sensor."""
|
||||
manager = hass.data[DATA_FFMPEG]
|
||||
|
||||
if not await manager.async_run_test(config.get(CONF_INPUT)):
|
||||
return
|
||||
|
||||
entity = FFmpegNoise(hass, manager, config)
|
||||
async_add_entities([entity])
|
||||
|
||||
|
|
|
@ -32,8 +32,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up a FFmpeg camera."""
|
||||
if not await hass.data[DATA_FFMPEG].async_run_test(config.get(CONF_INPUT)):
|
||||
return
|
||||
async_add_entities([FFmpegCamera(hass, config)])
|
||||
|
||||
|
||||
|
|
|
@ -74,9 +74,6 @@ SERVICE_PTZ_SCHEMA = vol.Schema({
|
|||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up a ONVIF camera."""
|
||||
if not hass.data[DATA_FFMPEG].async_run_test(config.get(CONF_HOST)):
|
||||
return
|
||||
|
||||
def handle_ptz(service):
|
||||
"""Handle PTZ service call."""
|
||||
pan = service.data.get(ATTR_PAN, None)
|
||||
|
@ -93,7 +90,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
for camera in target_cameras:
|
||||
camera.perform_ptz(pan, tilt, zoom)
|
||||
|
||||
hass.services.async_register(DOMAIN, SERVICE_PTZ, handle_ptz,
|
||||
hass.services.register(DOMAIN, SERVICE_PTZ, handle_ptz,
|
||||
schema=SERVICE_PTZ_SCHEMA)
|
||||
add_entities([ONVIFHassCamera(hass, config)])
|
||||
|
||||
|
|
|
@ -40,12 +40,11 @@ CONF_OUTPUT = 'output'
|
|||
CONF_RUN_TEST = 'run_test'
|
||||
|
||||
DEFAULT_BINARY = 'ffmpeg'
|
||||
DEFAULT_RUN_TEST = True
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Optional(CONF_FFMPEG_BIN, default=DEFAULT_BINARY): cv.string,
|
||||
vol.Optional(CONF_RUN_TEST, default=DEFAULT_RUN_TEST): cv.boolean,
|
||||
vol.Optional(CONF_RUN_TEST): cv.boolean,
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
@ -60,8 +59,7 @@ async def async_setup(hass, config):
|
|||
|
||||
manager = FFmpegManager(
|
||||
hass,
|
||||
conf.get(CONF_FFMPEG_BIN, DEFAULT_BINARY),
|
||||
conf.get(CONF_RUN_TEST, DEFAULT_RUN_TEST)
|
||||
conf.get(CONF_FFMPEG_BIN, DEFAULT_BINARY)
|
||||
)
|
||||
|
||||
# Register service
|
||||
|
@ -95,40 +93,17 @@ async def async_setup(hass, config):
|
|||
class FFmpegManager:
|
||||
"""Helper for ha-ffmpeg."""
|
||||
|
||||
def __init__(self, hass, ffmpeg_bin, run_test):
|
||||
def __init__(self, hass, ffmpeg_bin):
|
||||
"""Initialize helper."""
|
||||
self.hass = hass
|
||||
self._cache = {}
|
||||
self._bin = ffmpeg_bin
|
||||
self._run_test = run_test
|
||||
|
||||
@property
|
||||
def binary(self):
|
||||
"""Return ffmpeg binary from config."""
|
||||
return self._bin
|
||||
|
||||
async def async_run_test(self, input_source):
|
||||
"""Run test on this input. TRUE is deactivate or run correct.
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
from haffmpeg import Test
|
||||
|
||||
if self._run_test:
|
||||
# if in cache
|
||||
if input_source in self._cache:
|
||||
return self._cache[input_source]
|
||||
|
||||
# run test
|
||||
ffmpeg_test = Test(self.binary, loop=self.hass.loop)
|
||||
success = await ffmpeg_test.run_test(input_source)
|
||||
if not success:
|
||||
_LOGGER.error("FFmpeg '%s' test fails!", input_source)
|
||||
self._cache[input_source] = False
|
||||
return False
|
||||
self._cache[input_source] = True
|
||||
return True
|
||||
|
||||
|
||||
class FFmpegBase(Entity):
|
||||
"""Interface object for FFmpeg."""
|
||||
|
|
|
@ -15,9 +15,6 @@ class TestFFmpegNoiseSetup:
|
|||
self.hass = get_test_home_assistant()
|
||||
|
||||
self.config = {
|
||||
'ffmpeg': {
|
||||
'run_test': False,
|
||||
},
|
||||
'binary_sensor': {
|
||||
'platform': 'ffmpeg_noise',
|
||||
'input': 'testinputvideo',
|
||||
|
@ -80,9 +77,6 @@ class TestFFmpegMotionSetup:
|
|||
self.hass = get_test_home_assistant()
|
||||
|
||||
self.config = {
|
||||
'ffmpeg': {
|
||||
'run_test': False,
|
||||
},
|
||||
'binary_sensor': {
|
||||
'platform': 'ffmpeg_motion',
|
||||
'input': 'testinputvideo',
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""The tests for Home Assistant ffmpeg."""
|
||||
import asyncio
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import homeassistant.components.ffmpeg as ffmpeg
|
||||
from homeassistant.components.ffmpeg import (
|
||||
|
@ -10,7 +10,7 @@ from homeassistant.core import callback
|
|||
from homeassistant.setup import setup_component, async_setup_component
|
||||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, mock_coro)
|
||||
get_test_home_assistant, assert_setup_component)
|
||||
|
||||
|
||||
@callback
|
||||
|
@ -85,14 +85,14 @@ class TestFFmpegSetup:
|
|||
|
||||
def test_setup_component(self):
|
||||
"""Set up ffmpeg component."""
|
||||
with assert_setup_component(2):
|
||||
with assert_setup_component(1):
|
||||
setup_component(self.hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
assert self.hass.data[ffmpeg.DATA_FFMPEG].binary == 'ffmpeg'
|
||||
|
||||
def test_setup_component_test_service(self):
|
||||
"""Set up ffmpeg component test services."""
|
||||
with assert_setup_component(2):
|
||||
with assert_setup_component(1):
|
||||
setup_component(self.hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
assert self.hass.services.has_service(ffmpeg.DOMAIN, 'start')
|
||||
|
@ -103,7 +103,7 @@ class TestFFmpegSetup:
|
|||
@asyncio.coroutine
|
||||
def test_setup_component_test_register(hass):
|
||||
"""Set up ffmpeg component test register."""
|
||||
with assert_setup_component(2):
|
||||
with assert_setup_component(1):
|
||||
yield from async_setup_component(
|
||||
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
|
@ -118,7 +118,7 @@ def test_setup_component_test_register(hass):
|
|||
@asyncio.coroutine
|
||||
def test_setup_component_test_register_no_startup(hass):
|
||||
"""Set up ffmpeg component test register without startup."""
|
||||
with assert_setup_component(2):
|
||||
with assert_setup_component(1):
|
||||
yield from async_setup_component(
|
||||
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
|
@ -133,7 +133,7 @@ def test_setup_component_test_register_no_startup(hass):
|
|||
@asyncio.coroutine
|
||||
def test_setup_component_test_service_start(hass):
|
||||
"""Set up ffmpeg component test service start."""
|
||||
with assert_setup_component(2):
|
||||
with assert_setup_component(1):
|
||||
yield from async_setup_component(
|
||||
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
|
@ -149,7 +149,7 @@ def test_setup_component_test_service_start(hass):
|
|||
@asyncio.coroutine
|
||||
def test_setup_component_test_service_stop(hass):
|
||||
"""Set up ffmpeg component test service stop."""
|
||||
with assert_setup_component(2):
|
||||
with assert_setup_component(1):
|
||||
yield from async_setup_component(
|
||||
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
|
@ -165,7 +165,7 @@ def test_setup_component_test_service_stop(hass):
|
|||
@asyncio.coroutine
|
||||
def test_setup_component_test_service_restart(hass):
|
||||
"""Set up ffmpeg component test service restart."""
|
||||
with assert_setup_component(2):
|
||||
with assert_setup_component(1):
|
||||
yield from async_setup_component(
|
||||
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
|
@ -182,7 +182,7 @@ def test_setup_component_test_service_restart(hass):
|
|||
@asyncio.coroutine
|
||||
def test_setup_component_test_service_start_with_entity(hass):
|
||||
"""Set up ffmpeg component test service start."""
|
||||
with assert_setup_component(2):
|
||||
with assert_setup_component(1):
|
||||
yield from async_setup_component(
|
||||
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
|
@ -194,71 +194,3 @@ def test_setup_component_test_service_start_with_entity(hass):
|
|||
|
||||
assert ffmpeg_dev.called_start
|
||||
assert ffmpeg_dev.called_entities == ['test.ffmpeg_device']
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_component_test_run_test_false(hass):
|
||||
"""Set up ffmpeg component test run_test false."""
|
||||
with assert_setup_component(2):
|
||||
yield from async_setup_component(
|
||||
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {
|
||||
'run_test': False,
|
||||
}})
|
||||
|
||||
manager = hass.data[ffmpeg.DATA_FFMPEG]
|
||||
with patch('haffmpeg.Test.run_test', return_value=mock_coro(False)):
|
||||
yield from manager.async_run_test("blabalblabla")
|
||||
|
||||
assert len(manager._cache) == 0
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_component_test_run_test(hass):
|
||||
"""Set up ffmpeg component test run_test."""
|
||||
with assert_setup_component(2):
|
||||
yield from async_setup_component(
|
||||
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
manager = hass.data[ffmpeg.DATA_FFMPEG]
|
||||
|
||||
with patch('haffmpeg.Test.run_test', return_value=mock_coro(True)) \
|
||||
as mock_test:
|
||||
yield from manager.async_run_test("blabalblabla")
|
||||
|
||||
assert mock_test.called
|
||||
assert mock_test.call_count == 1
|
||||
assert len(manager._cache) == 1
|
||||
assert manager._cache['blabalblabla']
|
||||
|
||||
yield from manager.async_run_test("blabalblabla")
|
||||
|
||||
assert mock_test.called
|
||||
assert mock_test.call_count == 1
|
||||
assert len(manager._cache) == 1
|
||||
assert manager._cache['blabalblabla']
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_component_test_run_test_test_fail(hass):
|
||||
"""Set up ffmpeg component test run_test."""
|
||||
with assert_setup_component(2):
|
||||
yield from async_setup_component(
|
||||
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
|
||||
|
||||
manager = hass.data[ffmpeg.DATA_FFMPEG]
|
||||
|
||||
with patch('haffmpeg.Test.run_test', return_value=mock_coro(False)) \
|
||||
as mock_test:
|
||||
yield from manager.async_run_test("blabalblabla")
|
||||
|
||||
assert mock_test.called
|
||||
assert mock_test.call_count == 1
|
||||
assert len(manager._cache) == 1
|
||||
assert not manager._cache['blabalblabla']
|
||||
|
||||
yield from manager.async_run_test("blabalblabla")
|
||||
|
||||
assert mock_test.called
|
||||
assert mock_test.call_count == 1
|
||||
assert len(manager._cache) == 1
|
||||
assert not manager._cache['blabalblabla']
|
||||
|
|
Loading…
Reference in New Issue