mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Fetch media for events for rendering in the nest media player (#61056)
This commit is contained in:
parent
1a842d65ce
commit
5fdcbbe0e1
@ -86,6 +86,11 @@ PLATFORMS = ["sensor", "camera", "climate"]
|
|||||||
WEB_AUTH_DOMAIN = DOMAIN
|
WEB_AUTH_DOMAIN = DOMAIN
|
||||||
INSTALLED_AUTH_DOMAIN = f"{DOMAIN}.installed"
|
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):
|
class WebAuth(config_entry_oauth2_flow.LocalOAuth2Implementation):
|
||||||
"""OAuth implementation using OAuth for web applications."""
|
"""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)
|
subscriber = await api.new_subscriber(hass, entry)
|
||||||
if not subscriber:
|
if not subscriber:
|
||||||
return False
|
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)
|
callback = SignalUpdateCallback(hass)
|
||||||
subscriber.set_update_callback(callback.async_handle_event)
|
subscriber.set_update_callback(callback.async_handle_event)
|
||||||
|
@ -6,6 +6,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
from google_nest_sdm.device_manager import DeviceManager
|
from google_nest_sdm.device_manager import DeviceManager
|
||||||
from google_nest_sdm.event import EventMessage
|
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 google_nest_sdm.google_nest_subscriber import GoogleNestSubscriber
|
||||||
|
|
||||||
from homeassistant.components.nest import DOMAIN
|
from homeassistant.components.nest import DOMAIN
|
||||||
@ -98,6 +99,11 @@ class FakeSubscriber(GoogleNestSubscriber):
|
|||||||
"""Return the fake device manager."""
|
"""Return the fake device manager."""
|
||||||
return self._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):
|
def stop_async(self):
|
||||||
"""No-op to stop the subscriber."""
|
"""No-op to stop the subscriber."""
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user