mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Review AndroidTV tests for media player entity (#71168)
This commit is contained in:
parent
188040b8bb
commit
ea456893f9
@ -58,7 +58,6 @@ omit =
|
||||
homeassistant/components/amcrest/*
|
||||
homeassistant/components/ampio/*
|
||||
homeassistant/components/android_ip_webcam/*
|
||||
homeassistant/components/androidtv/__init__.py
|
||||
homeassistant/components/androidtv/diagnostics.py
|
||||
homeassistant/components/anel_pwrctrl/switch.py
|
||||
homeassistant/components/anthemav/media_player.py
|
||||
|
@ -1,8 +1,15 @@
|
||||
"""Define patches used for androidtv tests."""
|
||||
from unittest.mock import mock_open, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from androidtv.constants import CMD_DEVICE_PROPERTIES, CMD_MAC_ETH0, CMD_MAC_WLAN0
|
||||
|
||||
from homeassistant.components.androidtv.const import (
|
||||
DEFAULT_ADB_SERVER_PORT,
|
||||
DEVICE_ANDROIDTV,
|
||||
DEVICE_FIRETV,
|
||||
)
|
||||
|
||||
ADB_SERVER_HOST = "127.0.0.1"
|
||||
KEY_PYTHON = "python"
|
||||
KEY_SERVER = "server"
|
||||
|
||||
@ -36,7 +43,7 @@ class AdbDeviceTcpAsyncFake:
|
||||
class ClientAsyncFakeSuccess:
|
||||
"""A fake of the `ClientAsync` class when the connection and shell commands succeed."""
|
||||
|
||||
def __init__(self, host="127.0.0.1", port=5037):
|
||||
def __init__(self, host=ADB_SERVER_HOST, port=DEFAULT_ADB_SERVER_PORT):
|
||||
"""Initialize a `ClientAsyncFakeSuccess` instance."""
|
||||
self._devices = []
|
||||
|
||||
@ -50,7 +57,7 @@ class ClientAsyncFakeSuccess:
|
||||
class ClientAsyncFakeFail:
|
||||
"""A fake of the `ClientAsync` class when the connection and shell commands fail."""
|
||||
|
||||
def __init__(self, host="127.0.0.1", port=5037):
|
||||
def __init__(self, host=ADB_SERVER_HOST, port=DEFAULT_ADB_SERVER_PORT):
|
||||
"""Initialize a `ClientAsyncFakeFail` instance."""
|
||||
self._devices = []
|
||||
|
||||
@ -143,17 +150,34 @@ def patch_shell(response=None, error=False, mac_eth=False):
|
||||
}
|
||||
|
||||
|
||||
PATCH_ADB_DEVICE_TCP = patch(
|
||||
"androidtv.adb_manager.adb_manager_async.AdbDeviceTcpAsync", AdbDeviceTcpAsyncFake
|
||||
)
|
||||
PATCH_ANDROIDTV_OPEN = patch(
|
||||
"homeassistant.components.androidtv.media_player.open", mock_open()
|
||||
)
|
||||
PATCH_KEYGEN = patch("homeassistant.components.androidtv.keygen")
|
||||
PATCH_SIGNER = patch(
|
||||
"homeassistant.components.androidtv.ADBPythonSync.load_adbkey",
|
||||
return_value="signer for testing",
|
||||
)
|
||||
def patch_androidtv_update(
|
||||
state,
|
||||
current_app,
|
||||
running_apps,
|
||||
device,
|
||||
is_volume_muted,
|
||||
volume_level,
|
||||
hdmi_input,
|
||||
):
|
||||
"""Patch the `AndroidTV.update()` method."""
|
||||
return {
|
||||
DEVICE_ANDROIDTV: patch(
|
||||
"androidtv.androidtv.androidtv_async.AndroidTVAsync.update",
|
||||
return_value=(
|
||||
state,
|
||||
current_app,
|
||||
running_apps,
|
||||
device,
|
||||
is_volume_muted,
|
||||
volume_level,
|
||||
hdmi_input,
|
||||
),
|
||||
),
|
||||
DEVICE_FIRETV: patch(
|
||||
"androidtv.firetv.firetv_async.FireTVAsync.update",
|
||||
return_value=(state, current_app, running_apps, hdmi_input),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def isfile(filepath):
|
||||
@ -161,32 +185,12 @@ def isfile(filepath):
|
||||
return filepath.endswith("adbkey")
|
||||
|
||||
|
||||
def patch_firetv_update(state, current_app, running_apps, hdmi_input):
|
||||
"""Patch the `FireTV.update()` method."""
|
||||
return patch(
|
||||
"androidtv.firetv.firetv_async.FireTVAsync.update",
|
||||
return_value=(state, current_app, running_apps, hdmi_input),
|
||||
)
|
||||
|
||||
|
||||
def patch_androidtv_update(
|
||||
state, current_app, running_apps, device, is_volume_muted, volume_level, hdmi_input
|
||||
):
|
||||
"""Patch the `AndroidTV.update()` method."""
|
||||
return patch(
|
||||
"androidtv.androidtv.androidtv_async.AndroidTVAsync.update",
|
||||
return_value=(
|
||||
state,
|
||||
current_app,
|
||||
running_apps,
|
||||
device,
|
||||
is_volume_muted,
|
||||
volume_level,
|
||||
hdmi_input,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
PATCH_SETUP_ENTRY = patch(
|
||||
"homeassistant.components.androidtv.async_setup_entry",
|
||||
return_value=True,
|
||||
)
|
||||
PATCH_ACCESS = patch("homeassistant.components.androidtv.os.access", return_value=True)
|
||||
PATCH_ISFILE = patch("homeassistant.components.androidtv.os.path.isfile", isfile)
|
||||
PATCH_LAUNCH_APP = patch("androidtv.basetv.basetv_async.BaseTVAsync.launch_app")
|
||||
PATCH_STOP_APP = patch("androidtv.basetv.basetv_async.BaseTVAsync.stop_app")
|
||||
|
||||
|
@ -36,7 +36,7 @@ from homeassistant.components.androidtv.const import (
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_DEVICE_CLASS, CONF_HOST, CONF_PORT
|
||||
|
||||
from .patchers import isfile
|
||||
from .patchers import PATCH_ACCESS, PATCH_ISFILE, PATCH_SETUP_ENTRY
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@ -66,16 +66,6 @@ CONFIG_ADB_SERVER = {
|
||||
CONNECT_METHOD = (
|
||||
"homeassistant.components.androidtv.config_flow.async_connect_androidtv"
|
||||
)
|
||||
PATCH_ACCESS = patch(
|
||||
"homeassistant.components.androidtv.config_flow.os.access", return_value=True
|
||||
)
|
||||
PATCH_ISFILE = patch(
|
||||
"homeassistant.components.androidtv.config_flow.os.path.isfile", isfile
|
||||
)
|
||||
PATCH_SETUP_ENTRY = patch(
|
||||
"homeassistant.components.androidtv.async_setup_entry",
|
||||
return_value=True,
|
||||
)
|
||||
|
||||
|
||||
class MockConfigDevice:
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user