Fix Android TV 'async_get_media_image' (#40672)

pull/40712/head
Jeff Irion 2020-09-28 07:04:08 -07:00 committed by GitHub
parent ceded35a82
commit 68d75a879b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -502,14 +502,23 @@ class ADBDevice(MediaPlayerEntity):
return self._unique_id
@adb_decorator()
async def _adb_screencap(self):
"""Take a screen capture from the device."""
return await self.aftv.adb_screencap()
async def async_get_media_image(self):
"""Fetch current playing image."""
if not self._screencap or self.state in [STATE_OFF, None] or not self.available:
return None, None
media_data = await self.aftv.adb_screencap()
media_data = await self._adb_screencap()
if media_data:
return media_data, "image/png"
# If an exception occurred and the device is no longer available, write the state
if not self.available:
self.async_write_ha_state()
return None, None
@adb_decorator()

View File

@ -1064,6 +1064,21 @@ async def test_get_image(hass, hass_ws_client):
assert msg["result"]["content_type"] == "image/png"
assert msg["result"]["content"] == base64.b64encode(b"image").decode("utf-8")
with patch(
"androidtv.basetv.basetv_async.BaseTVAsync.adb_screencap",
side_effect=RuntimeError,
):
await client.send_json(
{"id": 6, "type": "media_player_thumbnail", "entity_id": entity_id}
)
msg = await client.receive_json()
# The device is unavailable, but getting the media image did not cause an exception
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNAVAILABLE
async def _test_service(
hass,