1 """Provides a binary sensor which is a collection of ffmpeg tools."""
3 from __future__
import annotations
7 from haffmpeg.core
import HAFFmpeg
8 import haffmpeg.sensor
as ffmpeg_sensor
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as BINARY_SENSOR_PLATFORM_SCHEMA,
13 BinarySensorDeviceClass,
31 CONF_CHANGES =
"changes"
32 CONF_REPEAT_TIME =
"repeat_time"
34 DEFAULT_NAME =
"FFmpeg Motion"
35 DEFAULT_INIT_STATE =
True
37 PLATFORM_SCHEMA = BINARY_SENSOR_PLATFORM_SCHEMA.extend(
39 vol.Required(CONF_INPUT): cv.string,
40 vol.Optional(CONF_INITIAL_STATE, default=DEFAULT_INIT_STATE): cv.boolean,
41 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
42 vol.Optional(CONF_EXTRA_ARGUMENTS): cv.string,
43 vol.Optional(CONF_RESET, default=10): vol.All(
44 vol.Coerce(int), vol.Range(min=1)
46 vol.Optional(CONF_CHANGES, default=10): vol.All(
47 vol.Coerce(float), vol.Range(min=0, max=99)
49 vol.Inclusive(CONF_REPEAT,
"repeat"): vol.All(
50 vol.Coerce(int), vol.Range(min=1)
52 vol.Inclusive(CONF_REPEAT_TIME,
"repeat"): vol.All(
53 vol.Coerce(int), vol.Range(min=1)
62 async_add_entities: AddEntitiesCallback,
63 discovery_info: DiscoveryInfoType |
None =
None,
65 """Set up the FFmpeg binary motion sensor."""
72 FFmpegBase[_HAFFmpegT], BinarySensorEntity
74 """A binary sensor which use FFmpeg for noise detection."""
76 def __init__(self, ffmpeg: _HAFFmpegT, config: dict[str, Any]) ->
None:
77 """Init for the binary sensor noise detection."""
78 super().
__init__(ffmpeg, config[CONF_INITIAL_STATE])
80 self._state: bool |
None =
False
82 self._name: str = config[CONF_NAME]
86 """HA-FFmpeg callback for noise detection."""
88 self.async_write_ha_state()
92 """Return true if the binary sensor is on."""
97 """Return the name of the entity."""
102 """A binary sensor which use FFmpeg for noise detection."""
105 self, hass: HomeAssistant, manager: FFmpegManager, config: dict[str, Any]
107 """Initialize FFmpeg motion binary sensor."""
108 ffmpeg = ffmpeg_sensor.SensorMotion(manager.binary, self._async_callback)
112 """Start a FFmpeg instance.
114 This method is a coroutine.
116 if entity_ids
is not None and self.entity_id
not in entity_ids:
120 self.ffmpeg.set_options(
121 time_reset=self._config[CONF_RESET],
122 time_repeat=self._config.
get(CONF_REPEAT_TIME, 0),
123 repeat=self._config.
get(CONF_REPEAT, 0),
124 changes=self._config[CONF_CHANGES],
128 await self.ffmpeg.open_sensor(
129 input_source=self._config[CONF_INPUT],
130 extra_cmd=self._config.
get(CONF_EXTRA_ARGUMENTS),
135 """Return the class of this sensor, from DEVICE_CLASSES."""
136 return BinarySensorDeviceClass.MOTION
None _async_start_ffmpeg(self, list[str]|None entity_ids)
BinarySensorDeviceClass device_class(self)
None __init__(self, HomeAssistant hass, FFmpegManager manager, dict[str, Any] config)
web.Response get(self, web.Request request, str config_key)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
None _async_callback(self, bool|None state)
None __init__(self, _HAFFmpegT ffmpeg, dict[str, Any] config)
FFmpegManager get_ffmpeg_manager(HomeAssistant hass)