Пример #1
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 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'
Пример #2
0
    def __init__(self, hass, manager, config):
        """Initialize FFmpeg noise binary sensor."""
        from haffmpeg import SensorNoise

        super().__init__(config)
        self.ffmpeg = SensorNoise(manager.binary, hass.loop,
                                  self._async_callback)
Пример #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 import SensorNoise

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

    @asyncio.coroutine
    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),
        )

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

    @property
    def device_class(self):
        """Return the class of this sensor, from DEVICE_CLASSES."""
        return 'sound'
Пример #4
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 import SensorNoise

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

    def async_start_ffmpeg(self):
        """Start a FFmpeg instance.

        This method must be run in the event loop and returns a coroutine.
        """
        # init config
        self.ffmpeg.set_options(
            time_duration=self._config.get(CONF_DURATION),
            time_reset=self._config.get(CONF_RESET),
            peak=self._config.get(CONF_PEAK),
        )

        # run
        return 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"
Пример #5
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 import SensorNoise

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

    def async_start_ffmpeg(self):
        """Start a FFmpeg instance.

        This method must be run in the event loop and returns a coroutine.
        """
        # init config
        self.ffmpeg.set_options(
            time_duration=self._config.get(CONF_DURATION),
            time_reset=self._config.get(CONF_RESET),
            peak=self._config.get(CONF_PEAK),
        )

        # run
        return 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 sensor_class(self):
        """Return the class of this sensor, from SENSOR_CLASSES."""
        return "sound"
Пример #6
0
    def __init__(self, hass, manager, config):
        """Initialize FFmpeg noise binary sensor."""
        from haffmpeg import SensorNoise

        super().__init__(config)
        self.ffmpeg = SensorNoise(
            manager.binary, hass.loop, self._async_callback)
Пример #7
0
def cli(ffmpeg, source, output, duration, reset, peak, extra, wait):
    """FFMPEG noise detection."""

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

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

    # wait
    sleep(wait)
    sensor.close()