Fetch media for events for rendering in the nest media player (#61056)

This commit is contained in:
Allen Porter 2021-12-05 09:45:40 -08:00 committed by GitHub
parent 1a842d65ce
commit 5fdcbbe0e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -86,6 +86,11 @@ PLATFORMS = ["sensor", "camera", "climate"]
WEB_AUTH_DOMAIN = DOMAIN
INSTALLED_AUTH_DOMAIN = f"{DOMAIN}.installed"
# Fetch media for events with an in memory cache. The largest media items
# are mp4 clips at ~90kb each, so this totals a few MB per camera.
# Note: Media for events can only be published within 30 seconds of the event
EVENT_MEDIA_CACHE_SIZE = 64
class WebAuth(config_entry_oauth2_flow.LocalOAuth2Implementation):
"""OAuth implementation using OAuth for web applications."""
@ -206,6 +211,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
subscriber = await api.new_subscriber(hass, entry)
if not subscriber:
return False
# Keep media for last N events in memory
subscriber.cache_policy.event_cache_size = EVENT_MEDIA_CACHE_SIZE
subscriber.cache_policy.fetch = True
callback = SignalUpdateCallback(hass)
subscriber.set_update_callback(callback.async_handle_event)

View File

@ -6,6 +6,7 @@ from unittest.mock import patch
from google_nest_sdm.device_manager import DeviceManager
from google_nest_sdm.event import EventMessage
from google_nest_sdm.event_media import CachePolicy
from google_nest_sdm.google_nest_subscriber import GoogleNestSubscriber
from homeassistant.components.nest import DOMAIN
@ -98,6 +99,11 @@ class FakeSubscriber(GoogleNestSubscriber):
"""Return the fake device manager."""
return self._device_manager
@property
def cache_policy(self) -> CachePolicy:
"""Return the cache policy."""
return self._device_manager.cache_policy
def stop_async(self):
"""No-op to stop the subscriber."""
return None