Add a lock on nest stream URL creation to avoid multiple in flight at once (#63212)
Add a lock to avoid multiple calls to create stream URLs when requests race in parallel to open streams. This is to avoid # of API calls on the nest server which can be rate limited, and to avoid any possibility of having too many streams per camera outstanding at once.pull/63404/head
parent
5c8e802cbf
commit
cb76a30233
|
@ -1,6 +1,7 @@
|
|||
"""Support for Google Nest SDM Cameras."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Callable
|
||||
import datetime
|
||||
import logging
|
||||
|
@ -74,6 +75,7 @@ class NestCamera(Camera):
|
|||
self._device = device
|
||||
self._device_info = NestDeviceInfo(device)
|
||||
self._stream: RtspStream | None = None
|
||||
self._create_stream_url_lock = asyncio.Lock()
|
||||
self._stream_refresh_unsub: Callable[[], None] | None = None
|
||||
# Cache of most recent event image
|
||||
self._event_id: str | None = None
|
||||
|
@ -140,6 +142,7 @@ class NestCamera(Camera):
|
|||
trait = self._device.traits[CameraLiveStreamTrait.NAME]
|
||||
if StreamingProtocol.RTSP not in trait.supported_protocols:
|
||||
return None
|
||||
async with self._create_stream_url_lock:
|
||||
if not self._stream:
|
||||
_LOGGER.debug("Fetching stream url")
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue