Esempio n. 1
0
    def __init__(self, hass, manager, config):
        """Initialize FFmpeg noise binary sensor."""
        from haffmpeg.sensor import SensorNoise

        super().__init__(config)
        self.ffmpeg = SensorNoise(manager.binary, hass.loop,
                                  self._async_callback)
Esempio n. 2
0
class FFmpegNoise(FFmpegBinarySensor):
    """A binary sensor which use FFmpeg for noise detection."""
    def __init__(self, hass, manager, config):
        """Initialize FFmpeg noise binary sensor."""
        from haffmpeg.sensor import SensorNoise

        super().__init__(config)
        self.ffmpeg = SensorNoise(manager.binary, hass.loop,
                                  self._async_callback)

    async def _async_start_ffmpeg(self, entity_ids):
        """Start a FFmpeg instance.

        This method is a coroutine.
        """
        if entity_ids is not None and self.entity_id not in entity_ids:
            return

        self.ffmpeg.set_options(
            time_duration=self._config.get(CONF_DURATION),
            time_reset=self._config.get(CONF_RESET),
            peak=self._config.get(CONF_PEAK),
        )

        await 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),
        )

    @property
    def device_class(self):
        """Return the class of this sensor, from DEVICE_CLASSES."""
        return 'sound'
Esempio n. 3
0
class FFmpegNoise(FFmpegBinarySensor):
    """A binary sensor which use FFmpeg for noise detection."""

    def __init__(self, hass, manager, config):
        """Initialize FFmpeg noise binary sensor."""
        from haffmpeg.sensor import SensorNoise

        super().__init__(config)
        self.ffmpeg = SensorNoise(
            manager.binary, hass.loop, self._async_callback)

    async def _async_start_ffmpeg(self, entity_ids):
        """Start a FFmpeg instance.

        This method is a coroutine.
        """
        if entity_ids is not None and self.entity_id not in entity_ids:
            return

        self.ffmpeg.set_options(
            time_duration=self._config.get(CONF_DURATION),
            time_reset=self._config.get(CONF_RESET),
            peak=self._config.get(CONF_PEAK),
        )

        await 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),
        )

    @property
    def device_class(self):
        """Return the class of this sensor, from DEVICE_CLASSES."""
        return 'sound'
Esempio n. 4
0
    def __init__(self, hass, manager, config):
        """Initialize FFmpeg noise binary sensor."""
        from haffmpeg.sensor import SensorNoise

        super().__init__(config)
        self.ffmpeg = SensorNoise(
            manager.binary, hass.loop, self._async_callback)
Esempio n. 5
0
def cli(ffmpeg, source, output, duration, reset, peak, extra):
    """FFMPEG noise detection."""
    loop = asyncio.get_event_loop()

    def callback(state):
        print("Noise detection is: %s" % str(state))

    sensor = SensorNoise(ffmpeg_bin=ffmpeg, loop=loop, callback=callback)
    sensor.set_options(time_duration=duration, time_reset=reset, peak=peak)
    loop.run_until_complete(
        sensor.open_sensor(input_source=source, output_dest=output, extra_cmd=extra)
    )

    # wait
    try:
        loop.run_forever()
    finally:
        loop.run_until_complete(sensor.close())
Esempio n. 6
0
def cli(ffmpeg, source, output, duration, reset, peak, extra):
    """FFMPEG noise detection."""
    loop = asyncio.get_event_loop()

    def callback(state):
        print("Noise detection is: %s" % str(state))

    sensor = SensorNoise(ffmpeg_bin=ffmpeg, loop=loop, callback=callback)
    sensor.set_options(time_duration=duration, time_reset=reset, peak=peak)
    loop.run_until_complete(
        sensor.open_sensor(input_source=source,
                           output_dest=output,
                           extra_cmd=extra))

    # wait
    try:
        loop.run_forever()
    finally:
        loop.run_until_complete(sensor.close())