Move ffmpeg to dispatcher from hass.data entity store. (#6211)
* Move ffmpeg to dispatcher from hass.data entity store. * fix lint * address paulus comments * add more unittest for better coverage
This commit is contained in:
parent
9490cb4c8f
commit
48cf7a4af9
5 changed files with 252 additions and 206 deletions
|
@ -54,9 +54,6 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||
|
||||
# generate sensor object
|
||||
entity = FFmpegNoise(hass, manager, config)
|
||||
|
||||
# add to system
|
||||
manager.async_register_device(entity)
|
||||
yield from async_add_devices([entity])
|
||||
|
||||
|
||||
|
@ -67,15 +64,19 @@ class FFmpegNoise(FFmpegBinarySensor):
|
|||
"""Initialize ffmpeg noise binary sensor."""
|
||||
from haffmpeg import SensorNoise
|
||||
|
||||
super().__init__(hass, config)
|
||||
super().__init__(config)
|
||||
self.ffmpeg = SensorNoise(
|
||||
manager.binary, hass.loop, self._async_callback)
|
||||
|
||||
def async_start_ffmpeg(self):
|
||||
@asyncio.coroutine
|
||||
def _async_start_ffmpeg(self, entity_ids):
|
||||
"""Start a FFmpeg instance.
|
||||
|
||||
This method must be run in the event loop and returns a coroutine.
|
||||
This method is a coroutine.
|
||||
"""
|
||||
if entity_ids is not None and self.entity_id not in entity_ids:
|
||||
return
|
||||
|
||||
# init config
|
||||
self.ffmpeg.set_options(
|
||||
time_duration=self._config.get(CONF_DURATION),
|
||||
|
@ -84,7 +85,7 @@ class FFmpegNoise(FFmpegBinarySensor):
|
|||
)
|
||||
|
||||
# run
|
||||
return self.ffmpeg.open_sensor(
|
||||
yield from self.ffmpeg.open_sensor(
|
||||
input_source=self._config.get(CONF_INPUT),
|
||||
output_dest=self._config.get(CONF_OUTPUT),
|
||||
extra_cmd=self._config.get(CONF_EXTRA_ARGUMENTS),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue