mirror of
https://github.com/home-assistant/core.git
synced 2025-11-06 17:40:11 +00:00
Update nest media player device thumbnails (#64738)
This commit is contained in:
@@ -377,9 +377,15 @@ class NestMediaSource(MediaSource):
|
||||
browse_root = _browse_root()
|
||||
browse_root.children = []
|
||||
for device_id, child_device in devices.items():
|
||||
browse_root.children.append(
|
||||
_browse_device(MediaId(device_id), child_device)
|
||||
)
|
||||
browse_device = _browse_device(MediaId(device_id), child_device)
|
||||
if last_event_id := await _async_get_recent_event_id(
|
||||
MediaId(device_id), child_device
|
||||
):
|
||||
browse_device.thumbnail = EVENT_THUMBNAIL_URL_FORMAT.format(
|
||||
device_id=last_event_id.device_id,
|
||||
event_token=last_event_id.event_token,
|
||||
)
|
||||
browse_root.children.append(browse_device)
|
||||
return browse_root
|
||||
|
||||
# Browse either a device or events within a device
|
||||
@@ -399,11 +405,9 @@ class NestMediaSource(MediaSource):
|
||||
browse_device.children = []
|
||||
for clip in clips.values():
|
||||
event_id = MediaId(media_id.device_id, clip.event_token)
|
||||
browse_event = _browse_clip_preview(event_id, device, clip)
|
||||
browse_device.children.append(browse_event)
|
||||
# Use thumbnail for first event in the list as the device thumbnail
|
||||
if browse_device.thumbnail is None:
|
||||
browse_device.thumbnail = browse_event.thumbnail
|
||||
browse_device.children.append(
|
||||
_browse_clip_preview(event_id, device, clip)
|
||||
)
|
||||
return browse_device
|
||||
|
||||
# Browse a specific event
|
||||
@@ -421,11 +425,9 @@ class NestMediaSource(MediaSource):
|
||||
browse_device.children = []
|
||||
for image in images.values():
|
||||
event_id = MediaId(media_id.device_id, image.event_token)
|
||||
browse_event = _browse_image_event(event_id, device, image)
|
||||
browse_device.children.append(browse_event)
|
||||
# Use thumbnail for first event in the list as the device thumbnail
|
||||
if browse_device.thumbnail is None:
|
||||
browse_device.thumbnail = browse_event.thumbnail
|
||||
browse_device.children.append(
|
||||
_browse_image_event(event_id, device, image)
|
||||
)
|
||||
return browse_device
|
||||
|
||||
# Browse a specific event
|
||||
@@ -470,6 +472,21 @@ def _browse_root() -> BrowseMediaSource:
|
||||
)
|
||||
|
||||
|
||||
async def _async_get_recent_event_id(
|
||||
device_id: MediaId, device: Device
|
||||
) -> MediaId | None:
|
||||
"""Return thumbnail for most recent device event."""
|
||||
if CameraClipPreviewTrait.NAME in device.traits:
|
||||
clips = await device.event_media_manager.async_clip_preview_sessions()
|
||||
if not clips:
|
||||
return None
|
||||
return MediaId(device_id.device_id, next(iter(clips)).event_token)
|
||||
images = await device.event_media_manager.async_image_sessions()
|
||||
if not images:
|
||||
return None
|
||||
return MediaId(device_id.device_id, next(iter(images)).event_token)
|
||||
|
||||
|
||||
def _browse_device(device_id: MediaId, device: Device) -> BrowseMediaSource:
|
||||
"""Return details for the specified device."""
|
||||
device_info = NestDeviceInfo(device)
|
||||
|
||||
Reference in New Issue
Block a user