2017-01-31 15:48:03 +00:00
|
|
|
"""The tests for Home Assistant ffmpeg binary sensor."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
2017-03-05 09:41:54 +00:00
|
|
|
from homeassistant.setup import setup_component
|
2017-01-31 15:48:03 +00:00
|
|
|
|
2019-12-09 10:48:22 +00:00
|
|
|
from tests.common import assert_setup_component, get_test_home_assistant, mock_coro
|
2017-01-31 15:48:03 +00:00
|
|
|
|
|
|
|
|
2018-07-20 08:45:20 +00:00
|
|
|
class TestFFmpegNoiseSetup:
|
2017-01-31 15:48:03 +00:00
|
|
|
"""Test class for ffmpeg."""
|
|
|
|
|
|
|
|
def setup_method(self):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
2017-01-31 15:48:03 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
|
|
|
|
|
|
|
self.config = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"binary_sensor": {"platform": "ffmpeg_noise", "input": "testinputvideo"}
|
2017-01-31 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def teardown_method(self):
|
|
|
|
"""Stop everything that was started."""
|
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
def test_setup_component(self):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up ffmpeg component."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with assert_setup_component(1, "binary_sensor"):
|
|
|
|
setup_component(self.hass, "binary_sensor", self.config)
|
2019-04-09 06:16:55 +00:00
|
|
|
self.hass.block_till_done()
|
2017-01-31 15:48:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert self.hass.data["ffmpeg"].binary == "ffmpeg"
|
|
|
|
assert self.hass.states.get("binary_sensor.ffmpeg_noise") is not None
|
2017-01-31 15:48:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@patch("haffmpeg.sensor.SensorNoise.open_sensor", return_value=mock_coro())
|
2017-01-31 15:48:03 +00:00
|
|
|
def test_setup_component_start(self, mock_start):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up ffmpeg component."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with assert_setup_component(1, "binary_sensor"):
|
|
|
|
setup_component(self.hass, "binary_sensor", self.config)
|
2019-04-09 06:16:55 +00:00
|
|
|
self.hass.block_till_done()
|
2017-01-31 15:48:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert self.hass.data["ffmpeg"].binary == "ffmpeg"
|
|
|
|
assert self.hass.states.get("binary_sensor.ffmpeg_noise") is not None
|
2017-01-31 15:48:03 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
|
|
|
assert mock_start.called
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
entity = self.hass.states.get("binary_sensor.ffmpeg_noise")
|
|
|
|
assert entity.state == "unavailable"
|
2017-02-26 22:31:46 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@patch("haffmpeg.sensor.SensorNoise")
|
2017-02-26 22:31:46 +00:00
|
|
|
def test_setup_component_start_callback(self, mock_ffmpeg):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up ffmpeg component."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with assert_setup_component(1, "binary_sensor"):
|
|
|
|
setup_component(self.hass, "binary_sensor", self.config)
|
2019-04-09 06:16:55 +00:00
|
|
|
self.hass.block_till_done()
|
2017-02-26 22:31:46 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert self.hass.data["ffmpeg"].binary == "ffmpeg"
|
|
|
|
assert self.hass.states.get("binary_sensor.ffmpeg_noise") is not None
|
2017-02-26 22:31:46 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
entity = self.hass.states.get("binary_sensor.ffmpeg_noise")
|
|
|
|
assert entity.state == "off"
|
2017-02-26 22:31:46 +00:00
|
|
|
|
2020-11-25 07:45:15 +00:00
|
|
|
self.hass.add_job(mock_ffmpeg.call_args[0][1], True)
|
2017-02-26 22:31:46 +00:00
|
|
|
self.hass.block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
entity = self.hass.states.get("binary_sensor.ffmpeg_noise")
|
|
|
|
assert entity.state == "on"
|
2017-01-31 15:48:03 +00:00
|
|
|
|
|
|
|
|
2018-07-20 08:45:20 +00:00
|
|
|
class TestFFmpegMotionSetup:
|
2017-01-31 15:48:03 +00:00
|
|
|
"""Test class for ffmpeg."""
|
|
|
|
|
|
|
|
def setup_method(self):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
2017-01-31 15:48:03 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
|
|
|
|
|
|
|
self.config = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"binary_sensor": {"platform": "ffmpeg_motion", "input": "testinputvideo"}
|
2017-01-31 15:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def teardown_method(self):
|
|
|
|
"""Stop everything that was started."""
|
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
def test_setup_component(self):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up ffmpeg component."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with assert_setup_component(1, "binary_sensor"):
|
|
|
|
setup_component(self.hass, "binary_sensor", self.config)
|
2019-04-09 06:16:55 +00:00
|
|
|
self.hass.block_till_done()
|
2017-01-31 15:48:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert self.hass.data["ffmpeg"].binary == "ffmpeg"
|
|
|
|
assert self.hass.states.get("binary_sensor.ffmpeg_motion") is not None
|
2017-01-31 15:48:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@patch("haffmpeg.sensor.SensorMotion.open_sensor", return_value=mock_coro())
|
2017-01-31 15:48:03 +00:00
|
|
|
def test_setup_component_start(self, mock_start):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up ffmpeg component."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with assert_setup_component(1, "binary_sensor"):
|
|
|
|
setup_component(self.hass, "binary_sensor", self.config)
|
2019-04-09 06:16:55 +00:00
|
|
|
self.hass.block_till_done()
|
2017-01-31 15:48:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert self.hass.data["ffmpeg"].binary == "ffmpeg"
|
|
|
|
assert self.hass.states.get("binary_sensor.ffmpeg_motion") is not None
|
2017-01-31 15:48:03 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
|
|
|
assert mock_start.called
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
entity = self.hass.states.get("binary_sensor.ffmpeg_motion")
|
|
|
|
assert entity.state == "unavailable"
|
2017-02-26 22:31:46 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@patch("haffmpeg.sensor.SensorMotion")
|
2017-02-26 22:31:46 +00:00
|
|
|
def test_setup_component_start_callback(self, mock_ffmpeg):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up ffmpeg component."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with assert_setup_component(1, "binary_sensor"):
|
|
|
|
setup_component(self.hass, "binary_sensor", self.config)
|
2019-04-09 06:16:55 +00:00
|
|
|
self.hass.block_till_done()
|
2017-02-26 22:31:46 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert self.hass.data["ffmpeg"].binary == "ffmpeg"
|
|
|
|
assert self.hass.states.get("binary_sensor.ffmpeg_motion") is not None
|
2017-02-26 22:31:46 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
entity = self.hass.states.get("binary_sensor.ffmpeg_motion")
|
|
|
|
assert entity.state == "off"
|
2017-02-26 22:31:46 +00:00
|
|
|
|
2020-11-25 07:45:15 +00:00
|
|
|
self.hass.add_job(mock_ffmpeg.call_args[0][1], True)
|
2017-02-26 22:31:46 +00:00
|
|
|
self.hass.block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
entity = self.hass.states.get("binary_sensor.ffmpeg_motion")
|
|
|
|
assert entity.state == "on"
|