diff --git a/homeassistant/components/androidtv/manifest.json b/homeassistant/components/androidtv/manifest.json index 9101e342a232cd..3ae3c64986fb4e 100644 --- a/homeassistant/components/androidtv/manifest.json +++ b/homeassistant/components/androidtv/manifest.json @@ -3,8 +3,8 @@ "name": "Android TV", "documentation": "https://www.home-assistant.io/integrations/androidtv", "requirements": [ - "adb-shell==0.1.1", - "androidtv==0.0.39", + "adb-shell==0.1.3", + "androidtv==0.0.40", "pure-python-adb==0.2.2.dev0" ], "codeowners": ["@JeffLIrion"] diff --git a/homeassistant/components/androidtv/media_player.py b/homeassistant/components/androidtv/media_player.py index f78d88ab3ecee9..80bcb4a9d9ae6c 100644 --- a/homeassistant/components/androidtv/media_player.py +++ b/homeassistant/components/androidtv/media_player.py @@ -1,5 +1,4 @@ """Support for functionality to interact with Android TV / Fire TV devices.""" -import binascii from datetime import datetime import functools import logging @@ -489,16 +488,8 @@ async def async_get_media_image(self): @adb_decorator() def get_raw_media_data(self): - """Raw base64 image data.""" - try: - response = self.aftv.adb_shell("screencap -p | base64") - except UnicodeDecodeError: - return None - - if isinstance(response, str) and response.strip(): - return binascii.a2b_base64(response.strip().replace("\n", "")) - - return None + """Retrieve a screenshot as binary .png image data.""" + return self.aftv.adb_screencap() @property def media_image_hash(self): diff --git a/requirements_all.txt b/requirements_all.txt index b104ae232a0d2f..9250855cd0803f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -119,7 +119,7 @@ adafruit-circuitpython-bmp280==3.1.1 adafruit-circuitpython-mcp230xx==2.2.2 # homeassistant.components.androidtv -adb-shell==0.1.1 +adb-shell==0.1.3 # homeassistant.components.adguard adguardhome==0.4.2 @@ -235,7 +235,7 @@ ambiclimate==0.2.1 amcrest==1.7.0 # homeassistant.components.androidtv -androidtv==0.0.39 +androidtv==0.0.40 # homeassistant.components.anel_pwrctrl anel_pwrctrl-homeassistant==0.0.1.dev2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 86e9c9a001b9f9..da9d0ba416b540 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -29,7 +29,7 @@ YesssSMS==0.4.1 abodepy==0.19.0 # homeassistant.components.androidtv -adb-shell==0.1.1 +adb-shell==0.1.3 # homeassistant.components.adguard adguardhome==0.4.2 @@ -106,7 +106,7 @@ airly==0.0.2 ambiclimate==0.2.1 # homeassistant.components.androidtv -androidtv==0.0.39 +androidtv==0.0.40 # homeassistant.components.apns apns2==0.3.0 diff --git a/tests/components/androidtv/test_media_player.py b/tests/components/androidtv/test_media_player.py index 82287877eaf0ba..c9f2c271000a85 100644 --- a/tests/components/androidtv/test_media_player.py +++ b/tests/components/androidtv/test_media_player.py @@ -1,4 +1,5 @@ """The tests for the androidtv platform.""" +import base64 import logging from unittest.mock import patch @@ -23,6 +24,7 @@ DOMAIN, SERVICE_SELECT_SOURCE, ) +from homeassistant.components.websocket_api.const import TYPE_RESULT from homeassistant.const import ( ATTR_ENTITY_ID, CONF_DEVICE_CLASS, @@ -968,3 +970,34 @@ async def test_androidtv_volume_set(hass): ) patch_set_volume_level.assert_called_with(0.5) + + +async def test_get_image(hass, hass_ws_client): + """Test taking a screen capture. + + This is based on `test_get_image` in tests/components/media_player/test_init.py. + """ + patch_key, entity_id = _setup(CONFIG_ANDROIDTV_ADB_SERVER) + + with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[ + patch_key + ], patchers.patch_shell("")[patch_key]: + assert await async_setup_component(hass, DOMAIN, CONFIG_ANDROIDTV_ADB_SERVER) + + with patchers.patch_shell("11")[patch_key]: + await hass.helpers.entity_component.async_update_entity(entity_id) + + client = await hass_ws_client(hass) + + with patch("androidtv.basetv.BaseTV.adb_screencap", return_value=b"image"): + await client.send_json( + {"id": 5, "type": "media_player_thumbnail", "entity_id": entity_id} + ) + + msg = await client.receive_json() + + assert msg["id"] == 5 + assert msg["type"] == TYPE_RESULT + assert msg["success"] + assert msg["result"]["content_type"] == "image/png" + assert msg["result"]["content"] == base64.b64encode(b"image").decode("utf-8")