Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions homeassistant/components/androidtv/media_player.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Support for functionality to interact with Android TV / Fire TV devices."""
import binascii
from datetime import datetime
import functools
import logging
import os
Expand Down Expand Up @@ -475,6 +477,32 @@ def unique_id(self):
"""Return the device unique id."""
return self._unique_id

async def async_get_media_image(self):
"""Fetch current playing image."""
media_data = self.get_raw_media_data()
Comment thread
i00 marked this conversation as resolved.
Outdated
if media_data:
return binascii.a2b_base64(media_data), "image/png"
Comment thread
i00 marked this conversation as resolved.
Outdated
return None, None

def get_raw_media_data(self):
"""Raw base64 image data."""
if self.state not in [STATE_OFF, None]:
Comment thread
i00 marked this conversation as resolved.
Outdated

try:
response = self.aftv.adb_shell("screencap -p | base64")
Comment thread
i00 marked this conversation as resolved.
Outdated
except UnicodeDecodeError:
return None

if isinstance(response, str) and response.strip():
return response.strip().replace("\n", "")

return None

@property
def media_image_url(self):
"""URL for obtaining a screen capture."""
return f"{datetime.now().timestamp()}"
Comment thread
i00 marked this conversation as resolved.

@adb_decorator()
def media_play(self):
"""Send play command."""
Expand Down