From 6889634edc2f4a669ef61aa12d94759efd9806aa Mon Sep 17 00:00:00 2001 From: Jeff Irion Date: Tue, 24 Sep 2019 07:07:28 -0700 Subject: [PATCH] Use the 'adb_shell' package instead of the 'adb' package (#97) * Working on porting to adb_shell package * Tests pass * Cleanup * Close the ADB connection when an exception occurs * Update requirements and HA imports * Linting (remove unnecessary pass) * 'default_timeout_s' -> 'timeout_s' * Add a test for 'ADBPython.close' * Set '_available' to False in 'ADBPython.close' * Don't set '_available' to False in 'ADBPython.close' * Don't check the '_available' attribute in 'test_close' * Bump adb-shell requirement to 0.0.2 * Change adb-shell timeout parameters to match adb parameters --- androidtv/adb_manager.py | 29 +++++++++++++------ setup.py | 2 +- tests/patchers.py | 57 +++++++++++++++++++------------------ tests/test_adb_manager.py | 28 ++++++++++++++++-- tests/test_androidtv.py | 16 +++++------ tests/test_basetv.py | 36 +++++++++++------------ tests/test_firetv.py | 6 ++-- tests/test_homeassistant.py | 17 +++++------ tests/test_setup.py | 18 ++++++------ 9 files changed, 123 insertions(+), 86 deletions(-) diff --git a/androidtv/adb_manager.py b/androidtv/adb_manager.py index 8efb5946..d199453d 100644 --- a/androidtv/adb_manager.py +++ b/androidtv/adb_manager.py @@ -11,8 +11,8 @@ import sys import threading -from adb.adb_commands import AdbCommands -from adb.sign_pythonrsa import PythonRSASigner +from adb_shell.adb_device import AdbDevice +from adb_shell.auth.sign_pythonrsa import PythonRSASigner from adb_messenger.client import Client _LOGGER = logging.getLogger(__name__) @@ -38,7 +38,7 @@ class ADBPython(object): def __init__(self, host, adbkey=''): self.host = host self.adbkey = adbkey - self._adb = None + self._adb = AdbDevice(serial=self.host, default_timeout_s=9.) # keep track of whether the ADB connection is intact self._available = False @@ -56,7 +56,13 @@ def available(self): Whether or not the ADB connection is intact """ - return bool(self._adb) + return self._adb.available + + def close(self): + """Close the ADB socket connection. + + """ + self._adb.close() def connect(self, always_log_errors=True): """Connect to an Android TV / Fire TV device. @@ -93,9 +99,9 @@ def connect(self, always_log_errors=True): signer = PythonRSASigner(pub, priv) # Connect to the device - self._adb = AdbCommands().ConnectDevice(serial=self.host, rsa_keys=[signer], default_timeout_ms=9000) + self._adb.connect(rsa_keys=[signer], auth_timeout_s=0.1) else: - self._adb = AdbCommands().ConnectDevice(serial=self.host, default_timeout_ms=9000) + self._adb.connect(auth_timeout_s=0.1) # ADB connection successfully established self._available = True @@ -108,7 +114,7 @@ def connect(self, always_log_errors=True): _LOGGER.warning("Couldn't connect to host %s, error: %s", self.host, serr.strerror) # ADB connection attempt failed - self._adb = None + self._adb.close() self._available = False finally: @@ -138,7 +144,7 @@ def shell(self, cmd): if self._adb_lock.acquire(**LOCK_KWARGS): # pylint: disable=unexpected-keyword-arg _LOGGER.debug("Sending command to %s via python-adb: %s", self.host, cmd) try: - return self._adb.Shell(cmd) + return self._adb.shell(cmd) finally: self._adb_lock.release() else: @@ -218,6 +224,13 @@ def available(self): self._available = False return False + def close(self): + """Close the ADB server socket connection. + + Currently, this doesn't do anything. + + """ + def connect(self, always_log_errors=True): """Connect to an Android TV / Fire TV device. diff --git a/setup.py b/setup.py index 82050206..2b6ef9b6 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ author='Jeff Irion', author_email='jefflirion@users.noreply.github.com', packages=['androidtv'], - install_requires=['rsa', 'adb-homeassistant>=1.3.2', 'pure-python-adb-homeassistant>=0.1.7.dev0'], + install_requires=['adb-shell>=0.0.2', 'pure-python-adb-homeassistant>=0.1.7.dev0', 'pyasn1', 'rsa'], classifiers=[ 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', diff --git a/tests/patchers.py b/tests/patchers.py index 4006a061..e6332dc0 100644 --- a/tests/patchers.py +++ b/tests/patchers.py @@ -8,32 +8,22 @@ from mock import patch -class AdbCommandsFake(object): - """A fake of the `adb.adb_commands.AdbCommands` class.""" +class AdbDeviceFake(object): + """A fake of the `adb_shell.adb_commands.AdbDevice` class.""" + def __init__(self, *args, **kwargs): + self.available = False - def ConnectDevice(self, *args, **kwargs): + def connect(self, *args, **kwargs): """Try to connect to a device.""" raise NotImplementedError - def Shell(self, cmd): + def shell(self, cmd): """Send an ADB shell command.""" - raise NotImplementedError - - -class AdbCommandsFakeSuccess(AdbCommandsFake): - """A fake of the `adb.adb_commands.AdbCommands` class when the connection attempt succeeds.""" - - def ConnectDevice(self, *args, **kwargs): - """Successfully connect to a device.""" - return self - - -class AdbCommandsFakeFail(AdbCommandsFake): - """A fake of the `adb.adb_commands.AdbCommands` class when the connection attempt fails.""" + return None - def ConnectDevice(self, *args, **kwargs): - """Fail to connect to a device.""" - raise socket_error + def close(self): + """Close the socket connection.""" + self.available = False class ClientFakeSuccess(object): @@ -85,23 +75,31 @@ def shell(self, cmd): def patch_connect(success): - """Mock the `adb.adb_commands.AdbCommands` and `adb_messenger.client.Client` classes.""" + """Mock the `adb_shell.adb_device.AdbDevice` and `adb_messenger.client.Client` classes.""" + + def connect_success_python(self, *args, **kwargs): + """Mock the `AdbDeviceFake.connect` method when it succeeds.""" + self.available = True + + def connect_fail_python(self, *args, **kwargs): + """Mock the `AdbDeviceFake.connect` method when it fails.""" + raise socket_error if success: - return {'python': patch('androidtv.adb_manager.AdbCommands', AdbCommandsFakeSuccess), 'server': patch('androidtv.adb_manager.Client', ClientFakeSuccess)} - return {'python': patch('androidtv.adb_manager.AdbCommands', AdbCommandsFakeFail), 'server': patch('androidtv.adb_manager.Client', ClientFakeFail)} + return {'python': patch('{}.AdbDeviceFake.connect'.format(__name__), connect_success_python), 'server': patch('androidtv.adb_manager.Client', ClientFakeSuccess)} + return {'python': patch('{}.AdbDeviceFake.connect'.format(__name__), connect_fail_python), 'server': patch('androidtv.adb_manager.Client', ClientFakeFail)} def patch_shell(response=None, error=False): - """Mock the `AdbCommandsFake.Shell` and `DeviceFake.shell` methods.""" + """Mock the `AdbDeviceFake.shell` and `DeviceFake.shell` methods.""" def shell_success(self, cmd): - """Mock the `AdbCommandsFake.Shell` and `DeviceFake.shell` methods when they are successful.""" + """Mock the `AdbDeviceFake.shell` and `DeviceFake.shell` methods when they are successful.""" self.shell_cmd = cmd return response def shell_fail_python(self, cmd): - """Mock the `AdbCommandsFake.Shell` method when it fails.""" + """Mock the `AdbDeviceFake.shell` method when it fails.""" self.shell_cmd = cmd raise AttributeError @@ -111,5 +109,8 @@ def shell_fail_server(self, cmd): raise ConnectionResetError if not error: - return {'python': patch('{}.AdbCommandsFake.Shell'.format(__name__), shell_success), 'server': patch('{}.DeviceFake.shell'.format(__name__), shell_success)} - return {'python': patch('{}.AdbCommandsFake.Shell'.format(__name__), shell_fail_python), 'server': patch('{}.DeviceFake.shell'.format(__name__), shell_fail_server)} + return {'python': patch('{}.AdbDeviceFake.shell'.format(__name__), shell_success), 'server': patch('{}.DeviceFake.shell'.format(__name__), shell_success)} + return {'python': patch('{}.AdbDeviceFake.shell'.format(__name__), shell_fail_python), 'server': patch('{}.DeviceFake.shell'.format(__name__), shell_fail_server)} + + +patch_adb_device = patch('androidtv.adb_manager.AdbDevice', AdbDeviceFake) diff --git a/tests/test_adb_manager.py b/tests/test_adb_manager.py index 3672d062..9cc83ba9 100644 --- a/tests/test_adb_manager.py +++ b/tests/test_adb_manager.py @@ -72,7 +72,8 @@ def setUp(self): """Create an `ADBPython` instance. """ - self.adb = ADBPython('IP:PORT') + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY]: + self.adb = ADBPython('IP:5555') def test_connect_success(self): """Test when the connect attempt is successful. @@ -123,7 +124,7 @@ def setUp(self): """Create an `ADBServer` instance. """ - self.adb = ADBServer('IP:PORT', 'ADB_SERVER_IP') + self.adb = ADBServer('IP:5555', 'ADB_SERVER_IP') def test_available(self): """Test that the ``available`` property works correctly. @@ -171,7 +172,8 @@ def setUp(self): """Create an `ADBPython` instance. """ - self.adb = ADBPython('IP:PORT', 'adbkey') + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY]: + self.adb = ADBPython('IP:5555', 'adbkey') def test_connect_success_with_priv_key(self): """Test when the connect attempt is successful when using a private key. @@ -190,3 +192,23 @@ def test_connect_success_with_priv_pub_key(self): self.assertTrue(self.adb.connect()) self.assertTrue(self.adb.available) self.assertTrue(self.adb._available) + + +class TestADBPythonClose(unittest.TestCase): + """Test the `ADBPython.close` method.""" + + PATCH_KEY = 'python' + + def test_close(self): + """Test the `ADBPython.close` method. + """ + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY]: + self.adb = ADBPython('IP:5555') + + with patchers.patch_connect(True)[self.PATCH_KEY]: + self.assertTrue(self.adb.connect()) + self.assertTrue(self.adb.available) + self.assertTrue(self.adb._available) + + self.adb.close() + self.assertFalse(self.adb.available) diff --git a/tests/test_androidtv.py b/tests/test_androidtv.py index 2bdbdc2a..9ebbbc2c 100644 --- a/tests/test_androidtv.py +++ b/tests/test_androidtv.py @@ -513,8 +513,8 @@ class TestAndroidTVPython(unittest.TestCase): ADB_ATTR = '_adb' def setUp(self): - with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: - self.atv = AndroidTV('IP:PORT') + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: + self.atv = AndroidTV('IP:5555') def test_turn_on_off(self): """Test that the ``AndroidTV.turn_on`` and ``AndroidTV.turn_off`` methods work correctly. @@ -982,7 +982,7 @@ class TestAndroidTVServer(TestAndroidTVPython): def setUp(self): with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: - self.atv = AndroidTV('IP:PORT', adb_server_ip='ADB_SERVER_IP') + self.atv = AndroidTV('IP:5555', adb_server_ip='ADB_SERVER_IP') class TestStateDetectionRulesValidator(unittest.TestCase): @@ -992,11 +992,11 @@ def test_state_detection_rules_validator(self): """ with patchers.patch_connect(True)['python'], patchers.patch_shell('')['python']: # Make sure that no error is raised when the state detection rules are valid - atv1 = AndroidTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES1) - atv2 = AndroidTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES2) - atv3 = AndroidTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES3) - atv4 = AndroidTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES4) - atv5 = AndroidTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES5) + atv1 = AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES1) + atv2 = AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES2) + atv3 = AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES3) + atv4 = AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES4) + atv5 = AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES5) if __name__ == "__main__": diff --git a/tests/test_basetv.py b/tests/test_basetv.py index 60e7b626..a02fbccf 100644 --- a/tests/test_basetv.py +++ b/tests/test_basetv.py @@ -87,8 +87,8 @@ class TestBaseTVPython(unittest.TestCase): ADB_ATTR = '_adb' def setUp(self): - with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: - self.btv = BaseTV('IP:PORT') + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: + self.btv = BaseTV('IP:5555') def test_available(self): """Test that the available property works correctly. @@ -394,24 +394,24 @@ def test_state_detection_rules_validator(self): """ with patchers.patch_connect(True)['python'], patchers.patch_shell('')['python']: # Make sure that no error is raised when the state detection rules are valid - btv1 = BaseTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES1) - btv2 = BaseTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES2) - btv3 = BaseTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES3) - btv4 = BaseTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES4) - btv5 = BaseTV('IP:PORT', state_detection_rules=STATE_DETECTION_RULES5) + btv1 = BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES1) + btv2 = BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES2) + btv3 = BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES3) + btv4 = BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES4) + btv5 = BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES5) # Make sure that an error is raised when the state detection rules are invalid - self.assertRaises(TypeError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID1) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID2) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID3) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID4) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID5) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID6) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID7) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID8) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID9) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID10) - self.assertRaises(KeyError, BaseTV, 'IP:PORT', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID11) + self.assertRaises(TypeError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID1) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID2) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID3) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID4) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID5) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID6) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID7) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID8) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID9) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID10) + self.assertRaises(KeyError, BaseTV, 'IP:5555', '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID11) def test_wake_lock_size(self): """Check that the ``wake_lock_size`` property works correctly. diff --git a/tests/test_firetv.py b/tests/test_firetv.py index 806271d1..9958be3a 100644 --- a/tests/test_firetv.py +++ b/tests/test_firetv.py @@ -128,8 +128,8 @@ class TestFireTVPython(unittest.TestCase): PATCH_KEY = 'python' def setUp(self): - with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: - self.ftv = FireTV('IP:PORT') + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: + self.ftv = FireTV('IP:5555') def test_turn_on_off(self): """Test that the ``FireTV.turn_on`` and ``FireTV.turn_off`` methods work correctly. @@ -414,7 +414,7 @@ class TestFireTVServer(TestFireTVPython): def setUp(self): with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: - self.ftv = FireTV('IP:PORT', adb_server_ip='ADB_SERVER_PORT') + self.ftv = FireTV('IP:5555', adb_server_ip='ADB_SERVER_PORT') if __name__ == "__main__": diff --git a/tests/test_homeassistant.py b/tests/test_homeassistant.py index 3d17c6ae..9aef5eba 100644 --- a/tests/test_homeassistant.py +++ b/tests/test_homeassistant.py @@ -58,6 +58,7 @@ def _adb_exception_catcher(self, *args, **kwargs): "establishing attempt in the next update. Error: %s", err, ) + self.aftv.adb.close() self._available = False # pylint: disable=protected-access return None @@ -86,12 +87,12 @@ def __init__(self, aftv, name, apps, turn_on_command, turn_off_command): # ADB exceptions to catch if not self.aftv.adb_server_ip: # Using "python-adb" (Python ADB implementation) - from adb.adb_protocol import ( + from adb_shell.exceptions import ( InvalidChecksumError, InvalidCommandError, InvalidResponseError, + TcpTimeoutException ) - from adb.usb_exceptions import TcpTimeoutException self.exceptions = ( AttributeError, @@ -240,8 +241,8 @@ class TestAndroidTVPythonImplementation(unittest.TestCase): def setUp(self): """Set up an `AndroidTVDevice` media player.""" - with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]: - aftv = setup("IP:PORT", device_class="androidtv") + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]: + aftv = setup("IP:5555", device_class="androidtv") self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, None, None) def test_reconnect(self): @@ -310,7 +311,7 @@ def setUp(self): """Set up an `AndroidTVDevice` media player.""" with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]: aftv = setup( - "IP:PORT", adb_server_ip="ADB_SERVER_IP", device_class="androidtv" + "IP:5555", adb_server_ip="ADB_SERVER_IP", device_class="androidtv" ) self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, None, None) @@ -370,8 +371,8 @@ class TestFireTVPythonImplementation(TestAndroidTVPythonImplementation): def setUp(self): """Set up a `FireTVDevice` media player.""" - with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]: - aftv = setup("IP:PORT", device_class="firetv") + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]: + aftv = setup("IP:5555", device_class="firetv") self.aftv = FireTVDevice(aftv, "Fake Fire TV", {}, True, None, None) @@ -383,6 +384,6 @@ def setUp(self): """Set up a `FireTVDevice` media player.""" with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]: aftv = setup( - "IP:PORT", adb_server_ip="ADB_SERVER_IP", device_class="firetv" + "IP:5555", adb_server_ip="ADB_SERVER_IP", device_class="firetv" ) self.aftv = FireTVDevice(aftv, "Fake Fire TV", {}, True, None, None) diff --git a/tests/test_setup.py b/tests/test_setup.py index b8764271..cad100c4 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -43,25 +43,25 @@ def test_setup(self): """Test that the ``setup`` function works correctly. """ with self.assertRaises(ValueError): - setup('IP:PORT', device_class='INVALID') + setup('IP:5555', device_class='INVALID') - with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]: - ftv = setup('IP:PORT') + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]: + ftv = setup('IP:5555') self.assertIsInstance(ftv, FireTV) self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1) - with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]: - atv = setup('IP:PORT') + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]: + atv = setup('IP:5555') self.assertIsInstance(atv, AndroidTV) self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2) - with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]: - ftv = setup('IP:PORT', device_class='androidtv') + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]: + ftv = setup('IP:5555', device_class='androidtv') self.assertIsInstance(ftv, AndroidTV) self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1) - with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]: - atv = setup('IP:PORT', device_class='firetv') + with patchers.patch_adb_device, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]: + atv = setup('IP:5555', device_class='firetv') self.assertIsInstance(atv, FireTV) self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)