1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00
This commit is contained in:
Paulus Schoutsen
2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View File

@@ -4,13 +4,16 @@ from unittest.mock import MagicMock
import homeassistant.components.ffmpeg as ffmpeg
from homeassistant.components.ffmpeg import (
DOMAIN, SERVICE_RESTART, SERVICE_START, SERVICE_STOP)
DOMAIN,
SERVICE_RESTART,
SERVICE_START,
SERVICE_STOP,
)
from homeassistant.const import ATTR_ENTITY_ID
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)
from tests.common import get_test_home_assistant, assert_setup_component
@callback
@@ -46,8 +49,7 @@ def async_restart(hass, entity_id=None):
class MockFFmpegDev(ffmpeg.FFmpegBase):
"""FFmpeg device mock."""
def __init__(self, hass, initial_state=True,
entity_id='test.ffmpeg_device'):
def __init__(self, hass, initial_state=True, entity_id="test.ffmpeg_device"):
"""Initialize mock."""
super().__init__(initial_state)
@@ -88,24 +90,23 @@ class TestFFmpegSetup:
with assert_setup_component(1):
setup_component(self.hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
assert self.hass.data[ffmpeg.DATA_FFMPEG].binary == 'ffmpeg'
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(1):
setup_component(self.hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
assert self.hass.services.has_service(ffmpeg.DOMAIN, 'start')
assert self.hass.services.has_service(ffmpeg.DOMAIN, 'stop')
assert self.hass.services.has_service(ffmpeg.DOMAIN, 'restart')
assert self.hass.services.has_service(ffmpeg.DOMAIN, "start")
assert self.hass.services.has_service(ffmpeg.DOMAIN, "stop")
assert self.hass.services.has_service(ffmpeg.DOMAIN, "restart")
@asyncio.coroutine
def test_setup_component_test_register(hass):
"""Set up ffmpeg component test register."""
with assert_setup_component(1):
yield from async_setup_component(
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
hass.bus.async_listen_once = MagicMock()
ffmpeg_dev = MockFFmpegDev(hass)
@@ -119,8 +120,7 @@ def test_setup_component_test_register(hass):
def test_setup_component_test_register_no_startup(hass):
"""Set up ffmpeg component test register without startup."""
with assert_setup_component(1):
yield from async_setup_component(
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
hass.bus.async_listen_once = MagicMock()
ffmpeg_dev = MockFFmpegDev(hass, False)
@@ -134,8 +134,7 @@ def test_setup_component_test_register_no_startup(hass):
def test_setup_component_test_service_start(hass):
"""Set up ffmpeg component test service start."""
with assert_setup_component(1):
yield from async_setup_component(
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
ffmpeg_dev = MockFFmpegDev(hass, False)
yield from ffmpeg_dev.async_added_to_hass()
@@ -150,8 +149,7 @@ def test_setup_component_test_service_start(hass):
def test_setup_component_test_service_stop(hass):
"""Set up ffmpeg component test service stop."""
with assert_setup_component(1):
yield from async_setup_component(
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
ffmpeg_dev = MockFFmpegDev(hass, False)
yield from ffmpeg_dev.async_added_to_hass()
@@ -166,8 +164,7 @@ def test_setup_component_test_service_stop(hass):
def test_setup_component_test_service_restart(hass):
"""Set up ffmpeg component test service restart."""
with assert_setup_component(1):
yield from async_setup_component(
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
ffmpeg_dev = MockFFmpegDev(hass, False)
yield from ffmpeg_dev.async_added_to_hass()
@@ -183,14 +180,13 @@ def test_setup_component_test_service_restart(hass):
def test_setup_component_test_service_start_with_entity(hass):
"""Set up ffmpeg component test service start."""
with assert_setup_component(1):
yield from async_setup_component(
hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
yield from async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}})
ffmpeg_dev = MockFFmpegDev(hass, False)
yield from ffmpeg_dev.async_added_to_hass()
async_start(hass, 'test.ffmpeg_device')
async_start(hass, "test.ffmpeg_device")
yield from hass.async_block_till_done()
assert ffmpeg_dev.called_start
assert ffmpeg_dev.called_entities == ['test.ffmpeg_device']
assert ffmpeg_dev.called_entities == ["test.ffmpeg_device"]