Handle overriding of default apps for Android TV (#41893)

* Handle overriding of default apps for Android TV

* Fix comment
pull/42883/head
Jeff Irion 2020-11-05 07:41:22 -08:00 committed by GitHub
parent 38495057a5
commit cfc8e96b15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -410,6 +410,12 @@ class ADBDevice(MediaPlayerEntity):
self._app_name_to_id = {
value: key for key, value in self._app_id_to_name.items() if value
}
# Make sure that apps overridden via the `apps` parameter are reflected
# in `self._app_name_to_id`
for key, value in apps.items():
self._app_name_to_id[value] = key
self._get_sources = get_sources
self._keys = KEYS

View File

@ -3,6 +3,7 @@ import base64
import copy
import logging
from androidtv.constants import APPS as ANDROIDTV_APPS
from androidtv.exceptions import LockNotAcquiredException
import pytest
@ -476,7 +477,11 @@ async def test_firetv_exclude_sources(hass):
async def _test_select_source(hass, config0, source, expected_arg, method_patch):
"""Test that the methods for launching and stopping apps are called correctly when selecting a source."""
config = copy.deepcopy(config0)
config[DOMAIN][CONF_APPS] = {"com.app.test1": "TEST 1", "com.app.test3": None}
config[DOMAIN][CONF_APPS] = {
"com.app.test1": "TEST 1",
"com.app.test3": None,
"com.youtube.test": "YouTube",
}
patch_key, entity_id = _setup(config)
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[
@ -545,6 +550,20 @@ async def test_androidtv_select_source_launch_app_hidden(hass):
)
async def test_androidtv_select_source_overridden_app_name(hass):
"""Test that when an app name is overridden via the `apps` configuration parameter, the app is launched correctly."""
# Evidence that the default YouTube app ID will be overridden
assert "YouTube" in ANDROIDTV_APPS.values()
assert "com.youtube.test" not in ANDROIDTV_APPS
assert await _test_select_source(
hass,
CONFIG_ANDROIDTV_ADB_SERVER,
"YouTube",
"com.youtube.test",
patchers.PATCH_LAUNCH_APP,
)
async def test_androidtv_select_source_stop_app_id(hass):
"""Test that an app can be stopped using its app ID."""
assert await _test_select_source(