Beispiel #1
0
async def async_setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    async_add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up an Amcrest IP Camera."""
    if discovery_info is None:
        return

    name = discovery_info[CONF_NAME]
    device = hass.data[DATA_AMCREST][DEVICES][name]
    entity = AmcrestCam(name, device, get_ffmpeg_manager(hass))

    # 2021.9.0 introduced unique id's for the camera entity, but these were not
    # unique for different resolution streams.  If any cameras were configured
    # with this version, update the old entity with the new unique id.
    serial_number = await device.api.async_serial_number
    serial_number = serial_number.strip()
    registry = entity_registry.async_get(hass)
    entity_id = registry.async_get_entity_id(CAMERA_DOMAIN, DOMAIN,
                                             serial_number)
    if entity_id is not None:
        _LOGGER.debug("Updating unique id for camera %s", entity_id)
        new_unique_id = f"{serial_number}-{device.resolution}-{device.channel}"
        registry.async_update_entity(entity_id, new_unique_id=new_unique_id)

    async_add_entities([entity], True)
Beispiel #2
0
 def __init__(
     self,
     hass: HomeAssistant,
     coordinator: EzvizDataUpdateCoordinator,
     serial: str,
     camera_username: str,
     camera_password: str | None,
     camera_rtsp_stream: str | None,
     local_rtsp_port: int,
     ffmpeg_arguments: str | None,
 ) -> None:
     """Initialize a Ezviz security camera."""
     super().__init__(coordinator, serial)
     Camera.__init__(self)
     self.stream_options[CONF_USE_WALLCLOCK_AS_TIMESTAMPS] = True
     self._username = camera_username
     self._password = camera_password
     self._rtsp_stream = camera_rtsp_stream
     self._local_rtsp_port = local_rtsp_port
     self._ffmpeg_arguments = ffmpeg_arguments
     self._ffmpeg = get_ffmpeg_manager(hass)
     self._attr_unique_id = serial
     self._attr_name = self.data["name"]
     if camera_password:
         self._attr_supported_features = CameraEntityFeature.STREAM
Beispiel #3
0
    async def handle_async_mjpeg_stream(
            self, request: web.Request) -> web.StreamResponse:
        """Generate an HTTP MJPEG stream from the latest recorded activity."""
        stream = CameraMjpeg(get_ffmpeg_manager(self.hass).binary)
        url = await self.coordinator.device.async_get_activity_video_url()
        await stream.open_camera(url, extra_cmd="-r 210")

        try:
            return await async_aiohttp_proxy_stream(
                self.hass,
                request,
                await stream.get_reader(),
                get_ffmpeg_manager(self.hass).ffmpeg_stream_content_type,
            )
        finally:
            await stream.close()
Beispiel #4
0
 def __init__(
     self,
     hass: HomeAssistant,
     coordinator: CanaryDataUpdateCoordinator,
     location_id: str,
     device: Device,
     ffmpeg_args: str,
 ) -> None:
     """Initialize a Canary security camera."""
     super().__init__(coordinator)
     Camera.__init__(self)
     self._ffmpeg: FFmpegManager = get_ffmpeg_manager(hass)
     self._ffmpeg_arguments = ffmpeg_args
     self._location_id = location_id
     self._device = device
     self._live_stream_session: LiveStreamSession | None = None
     self._attr_name = device.name
     self._attr_unique_id = str(device.device_id)
     self._attr_device_info = DeviceInfo(
         identifiers={(DOMAIN, str(device.device_id))},
         manufacturer=MANUFACTURER,
         model=device.device_type["name"],
         name=device.name,
     )
     self._image: bytes | None = None
     self._expires_at = dt_util.utcnow()
     _LOGGER.debug("%s %s has been initialized", self.name,
                   device.device_type["name"])
Beispiel #5
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry,
                            async_add_entities: AddEntitiesCallback) -> None:
    """Set up a Logi Circle Camera based on a config entry."""
    devices = await hass.data[LOGI_CIRCLE_DOMAIN].cameras
    ffmpeg = get_ffmpeg_manager(hass)

    cameras = [LogiCam(device, entry, ffmpeg) for device in devices]

    async_add_entities(cameras, True)
Beispiel #6
0
async def async_setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    async_add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the FFmpeg binary motion sensor."""
    manager = get_ffmpeg_manager(hass)
    entity = FFmpegMotion(hass, manager, config)
    async_add_entities([entity])
Beispiel #7
0
 def __init__(self, hass, camera, device_info):
     """Initialize an Arlo camera."""
     super().__init__()
     self._camera = camera
     self._attr_name = camera.name
     self._motion_status = False
     self._ffmpeg = get_ffmpeg_manager(hass)
     self._ffmpeg_arguments = device_info.get(CONF_FFMPEG_ARGUMENTS)
     self._last_refresh = None
     self.attrs = {}
Beispiel #8
0
 def __init__(self, hass, config):
     """Initialize."""
     super().__init__()
     self._extra_arguments = config.get(CONF_FFMPEG_ARGUMENTS)
     self._last_image = None
     self._last_url = None
     self._manager = get_ffmpeg_manager(hass)
     self._name = config[CONF_NAME]
     self._is_on = True
     self.host = config[CONF_HOST]
     self.port = config[CONF_PORT]
     self.path = config[CONF_PATH]
     self.user = config[CONF_USERNAME]
     self.passwd = config[CONF_PASSWORD]
Beispiel #9
0
async def async_setup_entry(
    hass: HomeAssistant,
    config_entry: ConfigEntry,
    async_add_entities: AddEntitiesCallback,
) -> None:
    """Set up a Ring Door Bell and StickUp Camera."""
    devices = hass.data[DOMAIN][config_entry.entry_id]["devices"]
    ffmpeg_manager = ffmpeg.get_ffmpeg_manager(hass)

    cams = []
    for camera in chain(devices["doorbots"], devices["authorized_doorbots"],
                        devices["stickup_cams"]):
        if not camera.has_subscription:
            continue

        cams.append(RingCam(config_entry.entry_id, ffmpeg_manager, camera))

    async_add_entities(cams)
Beispiel #10
0
 def __init__(
     self,
     hass: HomeAssistant,
     coordinator: EzvizDataUpdateCoordinator,
     serial: str,
     camera_username: str,
     camera_password: str | None,
     camera_rtsp_stream: str | None,
     local_rtsp_port: int,
     ffmpeg_arguments: str | None,
 ) -> None:
     """Initialize a Ezviz security camera."""
     super().__init__(coordinator, serial)
     Camera.__init__(self)
     self._username = camera_username
     self._password = camera_password
     self._rtsp_stream = camera_rtsp_stream
     self._local_rtsp_port = local_rtsp_port
     self._ffmpeg_arguments = ffmpeg_arguments
     self._ffmpeg = get_ffmpeg_manager(hass)
     self._attr_unique_id = serial
     self._attr_name = self.data["name"]
Beispiel #11
0
    async def handle_async_mjpeg_stream(self, request):
        """Generate an HTTP MJPEG stream from the camera."""
        LOGGER.debug("Handling mjpeg stream from camera '%s'", self.device.name)

        ffmpeg_manager = get_ffmpeg_manager(self.hass)
        stream = CameraMjpeg(ffmpeg_manager.binary)

        await stream.open_camera(
            self._stream_uri,
            extra_cmd=self.device.config_entry.options.get(CONF_EXTRA_ARGUMENTS),
        )

        try:
            stream_reader = await stream.get_reader()
            return await async_aiohttp_proxy_stream(
                self.hass,
                request,
                stream_reader,
                ffmpeg_manager.ffmpeg_stream_content_type,
            )
        finally:
            await stream.close()
async def async_get_transcoder(hass: HomeAssistant) -> Transcoder:
    """Get a nest clip transcoder."""
    media_path = hass.config.path(MEDIA_PATH)
    ffmpeg_manager = get_ffmpeg_manager(hass)
    return Transcoder(ffmpeg_manager.binary, media_path)
Beispiel #13
0
    def __init__(self, hass, driver, name, entity_id, aid, config):
        """Initialize a Camera accessory object."""
        self._ffmpeg = get_ffmpeg_manager(hass)
        for config_key, conf in CONFIG_DEFAULTS.items():
            if config_key not in config:
                config[config_key] = conf

        max_fps = config[CONF_MAX_FPS]
        max_width = config[CONF_MAX_WIDTH]
        max_height = config[CONF_MAX_HEIGHT]
        resolutions = [
            (w, h, fps)
            for w, h, fps in SLOW_RESOLUTIONS
            if w <= max_width and h <= max_height and fps < max_fps
        ] + [
            (w, h, max_fps)
            for w, h in RESOLUTIONS
            if w <= max_width and h <= max_height
        ]

        video_options = {
            "codec": {
                "profiles": [
                    VIDEO_CODEC_PARAM_PROFILE_ID_TYPES["BASELINE"],
                    VIDEO_CODEC_PARAM_PROFILE_ID_TYPES["MAIN"],
                    VIDEO_CODEC_PARAM_PROFILE_ID_TYPES["HIGH"],
                ],
                "levels": [
                    VIDEO_CODEC_PARAM_LEVEL_TYPES["TYPE3_1"],
                    VIDEO_CODEC_PARAM_LEVEL_TYPES["TYPE3_2"],
                    VIDEO_CODEC_PARAM_LEVEL_TYPES["TYPE4_0"],
                ],
            },
            "resolutions": resolutions,
        }
        audio_options = {
            "codecs": [
                {"type": "OPUS", "samplerate": 24},
                {"type": "OPUS", "samplerate": 16},
            ]
        }

        stream_address = config.get(CONF_STREAM_ADDRESS, driver.state.address)

        options = {
            "video": video_options,
            "audio": audio_options,
            "address": stream_address,
            "srtp": True,
            "stream_count": config[CONF_STREAM_COUNT],
        }

        super().__init__(
            hass,
            driver,
            name,
            entity_id,
            aid,
            config,
            category=CATEGORY_CAMERA,
            options=options,
        )

        self._char_motion_detected = None
        self.linked_motion_sensor = self.config.get(CONF_LINKED_MOTION_SENSOR)
        if self.linked_motion_sensor:
            state = self.hass.states.get(self.linked_motion_sensor)
            if state:
                serv_motion = self.add_preload_service(SERV_MOTION_SENSOR)
                self._char_motion_detected = serv_motion.configure_char(
                    CHAR_MOTION_DETECTED, value=False
                )
                self._async_update_motion_state(state)

        self._char_doorbell_detected = None
        self._char_doorbell_detected_switch = None
        self.linked_doorbell_sensor = self.config.get(CONF_LINKED_DOORBELL_SENSOR)
        if self.linked_doorbell_sensor:
            state = self.hass.states.get(self.linked_doorbell_sensor)
            if state:
                serv_doorbell = self.add_preload_service(SERV_DOORBELL)
                self.set_primary_service(serv_doorbell)
                self._char_doorbell_detected = serv_doorbell.configure_char(
                    CHAR_PROGRAMMABLE_SWITCH_EVENT,
                    value=0,
                )
                serv_stateless_switch = self.add_preload_service(
                    SERV_STATELESS_PROGRAMMABLE_SWITCH
                )
                self._char_doorbell_detected_switch = (
                    serv_stateless_switch.configure_char(
                        CHAR_PROGRAMMABLE_SWITCH_EVENT,
                        value=0,
                        valid_values={"SinglePress": DOORBELL_SINGLE_PRESS},
                    )
                )
                serv_speaker = self.add_preload_service(SERV_SPEAKER)
                serv_speaker.configure_char(CHAR_MUTE, value=0)

                self._async_update_doorbell_state(state)