Update logic for nest media source `can_play` for events (#61537)

pull/61627/head
Allen Porter 2021-12-12 14:10:20 -08:00 committed by GitHub
parent cbe58913ea
commit c3e72bec0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -24,7 +24,7 @@ import logging
from google_nest_sdm.camera_traits import CameraClipPreviewTrait, CameraEventImageTrait
from google_nest_sdm.device import Device
from google_nest_sdm.event import ImageEventBase
from google_nest_sdm.event import EventImageType, ImageEventBase
from homeassistant.components.media_player.const import (
MEDIA_CLASS_DIRECTORY,
@ -254,7 +254,7 @@ def _browse_event(
event_name=MEDIA_SOURCE_EVENT_TITLE_MAP.get(event.event_type, "Event"),
event_time=dt_util.as_local(event.timestamp).strftime(DATE_STR_FORMAT),
),
can_play=True,
can_play=(event.event_image_type == EventImageType.CLIP_PREVIEW),
can_expand=False,
thumbnail=None,
children=[],

View File

@ -231,6 +231,7 @@ async def test_camera_event(hass, auth, hass_client):
assert "Person" in browse.title
assert not browse.can_expand
assert not browse.children
assert not browse.can_play
# Resolving the event links to the media
media = await media_source.async_resolve_media(
@ -302,6 +303,7 @@ async def test_event_order(hass, auth):
event_timestamp_string = event_timestamp2.strftime(DATE_STR_FORMAT)
assert browse.children[0].title == f"Motion @ {event_timestamp_string}"
assert not browse.children[0].can_expand
assert not browse.can_play
# Person event is next
assert browse.children[1].domain == DOMAIN
@ -310,6 +312,7 @@ async def test_event_order(hass, auth):
event_timestamp_string = event_timestamp1.strftime(DATE_STR_FORMAT)
assert browse.children[1].title == f"Person @ {event_timestamp_string}"
assert not browse.children[1].can_expand
assert not browse.can_play
async def test_browse_invalid_device_id(hass, auth):
@ -449,6 +452,7 @@ async def test_camera_event_clip_preview(hass, auth, hass_client):
assert browse.children[0].title == f"Motion @ {event_timestamp_string}"
assert not browse.children[0].can_expand
assert len(browse.children[0].children) == 0
assert browse.children[0].can_play
# Resolving the event links to the media
media = await media_source.async_resolve_media(