Example #1
0
    def __init__(self, hass, manager, config):
        """Initialize FFmpeg motion binary sensor."""
        from haffmpeg.sensor import SensorMotion

        super().__init__(config)
        self.ffmpeg = SensorMotion(manager.binary, hass.loop,
                                   self._async_callback)
    def __init__(self, hass, manager, config):
        """Initialize FFmpeg motion binary sensor."""
        from haffmpeg.sensor import SensorMotion

        super().__init__(config)
        self.ffmpeg = SensorMotion(
            manager.binary, hass.loop, self._async_callback)
Example #3
0
def cli(ffmpeg, source, reset, repeat_time, repeat, changes, extra):
    """FFMPEG noise detection."""
    loop = asyncio.get_event_loop()

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

    sensor = SensorMotion(ffmpeg_bin=ffmpeg, loop=loop, callback=callback)
    sensor.set_options(
        time_reset=reset, changes=changes, repeat=repeat, time_repeat=repeat_time
    )
    loop.run_until_complete(sensor.open_sensor(input_source=source, extra_cmd=extra))

    # wait
    try:
        loop.run_forever()
    finally:
        loop.run_until_complete(sensor.close())
class FFmpegMotion(FFmpegBinarySensor):
    """A binary sensor which use FFmpeg for noise detection."""

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

        super().__init__(config)
        self.ffmpeg = SensorMotion(
            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

        # init config
        self.ffmpeg.set_options(
            time_reset=self._config.get(CONF_RESET),
            time_repeat=self._config.get(CONF_REPEAT_TIME, 0),
            repeat=self._config.get(CONF_REPEAT, 0),
            changes=self._config.get(CONF_CHANGES),
        )

        # run
        await self.ffmpeg.open_sensor(
            input_source=self._config.get(CONF_INPUT),
            extra_cmd=self._config.get(CONF_EXTRA_ARGUMENTS),
        )

    @property
    def device_class(self):
        """Return the class of this sensor, from DEVICE_CLASSES."""
        return 'motion'
Example #5
0
class FFmpegMotion(FFmpegBinarySensor):
    """A binary sensor which use FFmpeg for noise detection."""
    def __init__(self, hass, manager, config):
        """Initialize FFmpeg motion binary sensor."""
        from haffmpeg.sensor import SensorMotion

        super().__init__(config)
        self.ffmpeg = SensorMotion(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

        # init config
        self.ffmpeg.set_options(
            time_reset=self._config.get(CONF_RESET),
            time_repeat=self._config.get(CONF_REPEAT_TIME, 0),
            repeat=self._config.get(CONF_REPEAT, 0),
            changes=self._config.get(CONF_CHANGES),
        )

        # run
        await self.ffmpeg.open_sensor(
            input_source=self._config.get(CONF_INPUT),
            extra_cmd=self._config.get(CONF_EXTRA_ARGUMENTS),
        )

    @property
    def device_class(self):
        """Return the class of this sensor, from DEVICE_CLASSES."""
        return "motion"
Example #6
0
def cli(ffmpeg, source, reset, repeat_time, repeat, changes, extra):
    """FFMPEG noise detection."""
    loop = asyncio.get_event_loop()

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

    sensor = SensorMotion(ffmpeg_bin=ffmpeg, loop=loop, callback=callback)
    sensor.set_options(time_reset=reset,
                       changes=changes,
                       repeat=repeat,
                       time_repeat=repeat_time)
    loop.run_until_complete(
        sensor.open_sensor(input_source=source, extra_cmd=extra))

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