diff --git a/androidtv/__init__.py b/androidtv/__init__.py index 229e5d1f..c284f118 100644 --- a/androidtv/__init__.py +++ b/androidtv/__init__.py @@ -12,13 +12,15 @@ __version__ = '0.0.35' -def setup(host, adbkey='', adb_server_ip='', adb_server_port=5037, state_detection_rules=None, device_class='auto', auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S): +def setup(host, port=5555, adbkey='', adb_server_ip='', adb_server_port=5037, state_detection_rules=None, device_class='auto', auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S): """Connect to a device and determine whether it's an Android TV or an Amazon Fire TV. Parameters ---------- host : str - The address of the device in the format ``:`` + The address of the device; may be an IP address or a host name + port : int + The device port to which we are connecting (default is 5555) adbkey : str The path to the ``adbkey`` file for ADB authentication adb_server_ip : str @@ -39,15 +41,15 @@ def setup(host, adbkey='', adb_server_ip='', adb_server_port=5037, state_detecti """ if device_class == 'androidtv': - return AndroidTV(host, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) + return AndroidTV(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) if device_class == 'firetv': - return FireTV(host, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) + return FireTV(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) if device_class != 'auto': raise ValueError("`device_class` must be 'androidtv', 'firetv', or 'auto'.") - aftv = BaseTV(host, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) + aftv = BaseTV(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) # Fire TV if aftv.device_properties.get('manufacturer') == 'Amazon': diff --git a/androidtv/adb_manager.py b/androidtv/adb_manager.py index 8e4bd853..e6e36fc7 100644 --- a/androidtv/adb_manager.py +++ b/androidtv/adb_manager.py @@ -31,15 +31,18 @@ class ADBPython(object): Parameters ---------- host : str - The address of the device in the format ``:`` + The address of the device; may be an IP address or a host name + port : int + The device port to which we are connecting (default is 5555) adbkey : str The path to the ``adbkey`` file for ADB authentication """ - def __init__(self, host, adbkey=''): + def __init__(self, host, port, adbkey=''): self.host = host + self.port = int(port) self.adbkey = adbkey - self._adb = AdbDevice(serial=self.host, default_timeout_s=9.) + self._adb = AdbDevice(serial='{}:{}'.format(self.host, self.port), default_timeout_s=9.) # keep track of whether the ADB connection is intact self._available = False @@ -108,7 +111,7 @@ def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S) self._adb.connect(auth_timeout_s=auth_timeout_s) # ADB connection successfully established - _LOGGER.debug("ADB connection to %s successfully established", self.host) + _LOGGER.debug("ADB connection to %s:%d successfully established", self.host, self.port) self._available = True return True @@ -116,7 +119,7 @@ def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S) if self._available or always_log_errors: if exc.strerror is None: exc.strerror = "Timed out trying to connect to ADB device." - _LOGGER.warning("Couldn't connect to host %s. %s: %s", self.host, exc.__class__.__name__, exc.strerror) + _LOGGER.warning("Couldn't connect to %s:%d. %s: %s", self.host, self.port, exc.__class__.__name__, exc.strerror) # ADB connection attempt failed self.close() @@ -125,7 +128,7 @@ def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S) except Exception as exc: # pylint: disable=broad-except if self._available or always_log_errors: - _LOGGER.warning("Couldn't connect to host %s. %s: %s", self.host, exc.__class__.__name__, exc) + _LOGGER.warning("Couldn't connect to %s:%d. %s: %s", self.host, self.port, exc.__class__.__name__, exc) # ADB connection attempt failed self.close() @@ -136,7 +139,7 @@ def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S) self._adb_lock.release() # Lock could not be acquired - _LOGGER.warning("Couldn't connect to host %s because adb-shell lock not acquired.", self.host) + _LOGGER.warning("Couldn't connect to %s:%d because adb-shell lock not acquired.", self.host, self.port) self.close() self._available = False return False @@ -153,18 +156,18 @@ def pull(self, local_path, device_path): """ if not self.available: - _LOGGER.debug("ADB command not sent to %s because adb-shell connection is not established: pull(%s, %s)", self.host, local_path, device_path) + _LOGGER.debug("ADB command not sent to %s:%d because adb-shell connection is not established: pull(%s, %s)", self.host, self.port, local_path, device_path) return if self._adb_lock.acquire(**LOCK_KWARGS): # pylint: disable=unexpected-keyword-arg - _LOGGER.debug("Sending command to %s via adb-shell: pull(%s, %s)", self.host, local_path, device_path) + _LOGGER.debug("Sending command to %s:%d via adb-shell: pull(%s, %s)", self.host, self.port, local_path, device_path) try: self._adb.pull(device_path, local_path) finally: self._adb_lock.release() # Lock could not be acquired - _LOGGER.warning("ADB command not sent to %s because adb-shell lock not acquired: pull(%s, %s)", self.host, local_path, device_path) + _LOGGER.warning("ADB command not sent to %s:%d because adb-shell lock not acquired: pull(%s, %s)", self.host, self.port, local_path, device_path) return def push(self, local_path, device_path): @@ -179,18 +182,18 @@ def push(self, local_path, device_path): """ if not self.available: - _LOGGER.debug("ADB command not sent to %s because adb-shell connection is not established: push(%s, %s)", self.host, local_path, device_path) + _LOGGER.debug("ADB command not sent to %s:%d because adb-shell connection is not established: push(%s, %s)", self.host, self.port, local_path, device_path) return if self._adb_lock.acquire(**LOCK_KWARGS): # pylint: disable=unexpected-keyword-arg - _LOGGER.debug("Sending command to %s via adb-shell: push(%s, %s)", self.host, local_path, device_path) + _LOGGER.debug("Sending command to %s:%d via adb-shell: push(%s, %s)", self.host, self.port, local_path, device_path) try: self._adb.push(local_path, device_path) finally: self._adb_lock.release() # Lock could not be acquired - _LOGGER.warning("ADB command not sent to %s because adb-shell lock not acquired: push(%s, %s)", self.host, local_path, device_path) + _LOGGER.warning("ADB command not sent to %s:%d because adb-shell lock not acquired: push(%s, %s)", self.host, self.port, local_path, device_path) return def shell(self, cmd): @@ -208,18 +211,18 @@ def shell(self, cmd): """ if not self.available: - _LOGGER.debug("ADB command not sent to %s because adb-shell connection is not established: %s", self.host, cmd) + _LOGGER.debug("ADB command not sent to %s:%d because adb-shell connection is not established: %s", self.host, self.port, cmd) return None if self._adb_lock.acquire(**LOCK_KWARGS): # pylint: disable=unexpected-keyword-arg - _LOGGER.debug("Sending command to %s via adb-shell: %s", self.host, cmd) + _LOGGER.debug("Sending command to %s:%d via adb-shell: %s", self.host, self.port, cmd) try: return self._adb.shell(cmd) finally: self._adb_lock.release() # Lock could not be acquired - _LOGGER.warning("ADB command not sent to %s because adb-shell lock not acquired: %s", self.host, cmd) + _LOGGER.warning("ADB command not sent to %s:%d because adb-shell lock not acquired: %s", self.host, self.port, cmd) return None @@ -229,17 +232,18 @@ class ADBServer(object): Parameters ---------- host : str - The address of the device in the format ``:`` - adbkey : str - The path to the ``adbkey`` file for ADB authentication + The address of the device; may be an IP address or a host name + port : int + The device port to which we are connecting (default is 5555) adb_server_ip : str The IP address of the ADB server adb_server_port : int The port for the ADB server """ - def __init__(self, host, adb_server_ip='', adb_server_port=5037): + def __init__(self, host, port=5555, adb_server_ip='', adb_server_port=5037): self.host = host + self.port = int(port) self.adb_server_ip = adb_server_ip self.adb_server_port = adb_server_port self._adb_client = None @@ -271,7 +275,8 @@ def available(self): # make sure the device is available try: # case 1: the device is currently available - if any([self.host in dev.get_serial_no() for dev in adb_devices]): + host_port = '{}:{}'.format(self.host, self.port) + if any([host_port in dev.get_serial_no() for dev in adb_devices]): if not self._available: self._available = True return True @@ -327,17 +332,17 @@ def connect(self, always_log_errors=True): # Catch exceptions try: self._adb_client = Client(host=self.adb_server_ip, port=self.adb_server_port) - self._adb_device = self._adb_client.device(self.host) + self._adb_device = self._adb_client.device('{}:{}'.format(self.host, self.port)) # ADB connection successfully established if self._adb_device: - _LOGGER.debug("ADB connection to %s via ADB server %s:%s successfully established", self.host, self.adb_server_ip, self.adb_server_port) + _LOGGER.debug("ADB connection to %s:%d via ADB server %s:%d successfully established", self.host, self.port, self.adb_server_ip, self.adb_server_port) self._available = True return True # ADB connection attempt failed (without an exception) if self._available or always_log_errors: - _LOGGER.warning("Couldn't connect to host %s via ADB server %s:%s", self.host, self.adb_server_ip, self.adb_server_port) + _LOGGER.warning("Couldn't connect to %s:%d via ADB server %s:%d", self.host, self.port, self.adb_server_ip, self.adb_server_port) self.close() self._available = False @@ -346,7 +351,7 @@ def connect(self, always_log_errors=True): # ADB connection attempt failed except Exception as exc: # noqa pylint: disable=broad-except if self._available or always_log_errors: - _LOGGER.warning("Couldn't connect to host %s via ADB server %s:%s, error: %s", self.host, self.adb_server_ip, self.adb_server_port, exc) + _LOGGER.warning("Couldn't connect to %s:%d via ADB server %s:%d, error: %s", self.host, self.port, self.adb_server_ip, self.adb_server_port, exc) self.close() self._available = False @@ -356,7 +361,7 @@ def connect(self, always_log_errors=True): self._adb_lock.release() # Lock could not be acquired - _LOGGER.warning("Couldn't connect to host %s via ADB server %s:%s because pure-python-adb lock not acquired.", self.host, self.adb_server_ip, self.adb_server_port) + _LOGGER.warning("Couldn't connect to %s:%d via ADB server %s:%d because pure-python-adb lock not acquired.", self.host, self.port, self.adb_server_ip, self.adb_server_port) self.close() self._available = False return False @@ -373,18 +378,18 @@ def pull(self, local_path, device_path): """ if not self.available: - _LOGGER.debug("ADB command not sent to %s via ADB server %s:%s because pure-python-adb connection is not established: pull(%s, %s)", self.host, self.adb_server_ip, self.adb_server_port, local_path, device_path) + _LOGGER.debug("ADB command not sent to %s:%d via ADB server %s:%d because pure-python-adb connection is not established: pull(%s, %s)", self.host, self.port, self.adb_server_ip, self.adb_server_port, local_path, device_path) return if self._adb_lock.acquire(**LOCK_KWARGS): # pylint: disable=unexpected-keyword-arg - _LOGGER.debug("Sending command to %s via ADB server %s:%s: pull(%s, %s)", self.host, self.adb_server_ip, self.adb_server_port, local_path, device_path) + _LOGGER.debug("Sending command to %s:%d via ADB server %s:%d: pull(%s, %s)", self.host, self.port, self.adb_server_ip, self.adb_server_port, local_path, device_path) try: self._adb_device.pull(device_path, local_path) finally: self._adb_lock.release() # Lock could not be acquired - _LOGGER.warning("ADB command not sent to %s via ADB server %s:%s: pull(%s, %s)", self.host, self.adb_server_ip, self.adb_server_port, local_path, device_path) + _LOGGER.warning("ADB command not sent to %s:%d via ADB server %s:%d: pull(%s, %s)", self.host, self.port, self.adb_server_ip, self.adb_server_port, local_path, device_path) return def push(self, local_path, device_path): @@ -399,18 +404,18 @@ def push(self, local_path, device_path): """ if not self.available: - _LOGGER.debug("ADB command not sent to %s via ADB server %s:%s because pure-python-adb connection is not established: push(%s, %s)", self.host, self.adb_server_ip, self.adb_server_port, local_path, device_path) + _LOGGER.debug("ADB command not sent to %s:%d via ADB server %s:%d because pure-python-adb connection is not established: push(%s, %s)", self.host, self.port, self.adb_server_ip, self.adb_server_port, local_path, device_path) return if self._adb_lock.acquire(**LOCK_KWARGS): # pylint: disable=unexpected-keyword-arg - _LOGGER.debug("Sending command to %s via ADB server %s:%s: push(%s, %s)", self.host, self.adb_server_ip, self.adb_server_port, local_path, device_path) + _LOGGER.debug("Sending command to %s:%d via ADB server %s:%d: push(%s, %s)", self.host, self.port, self.adb_server_ip, self.adb_server_port, local_path, device_path) try: self._adb_device.push(local_path, device_path) finally: self._adb_lock.release() # Lock could not be acquired - _LOGGER.warning("ADB command not sent to %s via ADB server %s:%s: push(%s, %s)", self.host, self.adb_server_ip, self.adb_server_port, local_path, device_path) + _LOGGER.warning("ADB command not sent to %s:%d via ADB server %s:%d: push(%s, %s)", self.host, self.port, self.adb_server_ip, self.adb_server_port, local_path, device_path) return def shell(self, cmd): @@ -428,16 +433,16 @@ def shell(self, cmd): """ if not self._available: - _LOGGER.debug("ADB command not sent to %s via ADB server %s:%s because pure-python-adb connection is not established: %s", self.host, self.adb_server_ip, self.adb_server_port, cmd) + _LOGGER.debug("ADB command not sent to %s:%d via ADB server %s:%d because pure-python-adb connection is not established: %s", self.host, self.port, self.adb_server_ip, self.adb_server_port, cmd) return None if self._adb_lock.acquire(**LOCK_KWARGS): # pylint: disable=unexpected-keyword-arg - _LOGGER.debug("Sending command to %s via ADB server %s:%s: %s", self.host, self.adb_server_ip, self.adb_server_port, cmd) + _LOGGER.debug("Sending command to %s:%d via ADB server %s:%d: %s", self.host, self.port, self.adb_server_ip, self.adb_server_port, cmd) try: return self._adb_device.shell(cmd) finally: self._adb_lock.release() # Lock could not be acquired - _LOGGER.warning("ADB command not sent to %s via ADB server %s:%s because pure-python-adb lock not acquired: %s", self.host, self.adb_server_ip, self.adb_server_port, cmd) + _LOGGER.warning("ADB command not sent to %s:%d via ADB server %s:%d because pure-python-adb lock not acquired: %s", self.host, self.port, self.adb_server_ip, self.adb_server_port, cmd) return None diff --git a/androidtv/androidtv.py b/androidtv/androidtv.py index 0d22d211..b0601a72 100644 --- a/androidtv/androidtv.py +++ b/androidtv/androidtv.py @@ -18,7 +18,9 @@ class AndroidTV(BaseTV): Parameters ---------- host : str - The address of the device in the format ``:`` + The address of the device; may be an IP address or a host name + port : int + The device port to which we are connecting (default is 5555) adbkey : str The path to the ``adbkey`` file for ADB authentication adb_server_ip : str @@ -34,8 +36,8 @@ class AndroidTV(BaseTV): DEVICE_CLASS = 'androidtv' - def __init__(self, host, adbkey='', adb_server_ip='', adb_server_port=5037, state_detection_rules=None, auth_timeout_s=constants.DEFAULT_AUTH_TIMEOUT_S): - BaseTV.__init__(self, host, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) + def __init__(self, host, port=5555, adbkey='', adb_server_ip='', adb_server_port=5037, state_detection_rules=None, auth_timeout_s=constants.DEFAULT_AUTH_TIMEOUT_S): + BaseTV.__init__(self, host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) # ======================================================================= # # # @@ -230,7 +232,7 @@ def get_properties(self, get_running_apps=True, lazy=False): output = self._adb.shell(constants.CMD_ANDROIDTV_PROPERTIES_NOT_LAZY_RUNNING_APPS) else: output = self._adb.shell(constants.CMD_ANDROIDTV_PROPERTIES_NOT_LAZY_NO_RUNNING_APPS) - _LOGGER.debug("Android TV %s `get_properties` response: %s", self.host, output) + _LOGGER.debug("Android TV %s:%d `get_properties` response: %s", self.host, self.port, output) # ADB command was unsuccessful if output is None: diff --git a/androidtv/basetv.py b/androidtv/basetv.py index 610aa64d..d9360be0 100644 --- a/androidtv/basetv.py +++ b/androidtv/basetv.py @@ -51,7 +51,9 @@ class BaseTV(object): Parameters ---------- host : str - The address of the device in the format ``:`` + The address of the device; may be an IP address or a host name + port : int + The device port to which we are connecting (default is 5555) adbkey : str The path to the ``adbkey`` file for ADB authentication adb_server_ip : str @@ -65,8 +67,9 @@ class BaseTV(object): """ - def __init__(self, host, adbkey='', adb_server_ip='', adb_server_port=5037, state_detection_rules=None, auth_timeout_s=constants.DEFAULT_AUTH_TIMEOUT_S): + def __init__(self, host, port=5555, adbkey='', adb_server_ip='', adb_server_port=5037, state_detection_rules=None, auth_timeout_s=constants.DEFAULT_AUTH_TIMEOUT_S): self.host = host + self.port = int(port) self.adbkey = adbkey self.adb_server_ip = adb_server_ip self.adb_server_port = adb_server_port @@ -85,10 +88,10 @@ def __init__(self, host, adbkey='', adb_server_ip='', adb_server_port=5037, stat # the handler for ADB commands if not adb_server_ip: # python-adb - self._adb = ADBPython(host, adbkey) + self._adb = ADBPython(host, port, adbkey) else: # pure-python-adb - self._adb = ADBServer(host, adb_server_ip, adb_server_port) + self._adb = ADBServer(host, port, adb_server_ip, adb_server_port) # establish the ADB connection self.adb_connect(auth_timeout_s=auth_timeout_s) @@ -202,7 +205,7 @@ def get_device_properties(self): constants.CMD_MAC_WLAN0 + " && " + constants.CMD_MAC_ETH0) - _LOGGER.debug("%s `get_device_properties` response: %s", self.host, properties) + _LOGGER.debug("%s:%d `get_device_properties` response: %s", self.host, self.port, properties) if not properties: return {} @@ -214,7 +217,7 @@ def get_device_properties(self): manufacturer, model, serialno, version, mac_wlan0_output, mac_eth0_output = lines if not serialno.strip(): - _LOGGER.warning("Could not obtain serialno for %s, got: '%s'", self.host, serialno) + _LOGGER.warning("Could not obtain serialno for %s:%d, got: '%s'", self.host, self.port, serialno) serialno = None mac_wlan0_matches = re.findall(constants.MAC_REGEX_PATTERN, mac_wlan0_output) diff --git a/androidtv/firetv.py b/androidtv/firetv.py index ef637b1d..64da90f1 100644 --- a/androidtv/firetv.py +++ b/androidtv/firetv.py @@ -15,27 +15,29 @@ class FireTV(BaseTV): """Representation of an Amazon Fire TV device. - Parameters - ---------- - host : str - The address of the device in the format ``:`` - adbkey : str - The path to the ``adbkey`` file for ADB authentication - adb_server_ip : str - The IP address of the ADB server - adb_server_port : int - The port for the ADB server - state_detection_rules : dict, None - A dictionary of rules for determining the state (see :class:`~androidtv.basetv.BaseTV`) - auth_timeout_s : float - Authentication timeout (in seconds) - - """ + Parameters + ---------- + host : str + The address of the device; may be an IP address or a host name + port : int + The device port to which we are connecting (default is 5555) + adbkey : str + The path to the ``adbkey`` file for ADB authentication + adb_server_ip : str + The IP address of the ADB server + adb_server_port : int + The port for the ADB server + state_detection_rules : dict, None + A dictionary of rules for determining the state (see :class:`~androidtv.basetv.BaseTV`) + auth_timeout_s : float + Authentication timeout (in seconds) + + """ DEVICE_CLASS = 'firetv' - def __init__(self, host, adbkey='', adb_server_ip='', adb_server_port=5037, state_detection_rules=None, auth_timeout_s=constants.DEFAULT_AUTH_TIMEOUT_S): - BaseTV.__init__(self, host, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) + def __init__(self, host, port=5555, adbkey='', adb_server_ip='', adb_server_port=5037, state_detection_rules=None, auth_timeout_s=constants.DEFAULT_AUTH_TIMEOUT_S): + BaseTV.__init__(self, host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, auth_timeout_s) # ======================================================================= # # # @@ -249,7 +251,7 @@ def get_properties(self, get_running_apps=True, lazy=False): output = self._adb.shell(constants.CMD_FIRETV_PROPERTIES_NOT_LAZY_RUNNING_APPS) else: output = self._adb.shell(constants.CMD_FIRETV_PROPERTIES_NOT_LAZY_NO_RUNNING_APPS) - _LOGGER.debug("Fire TV %s `get_properties` response: %s", self.host, output) + _LOGGER.debug("Fire TV %s:%d `get_properties` response: %s", self.host, self.port, output) # ADB command was unsuccessful if output is None: diff --git a/tests/test_adb_manager.py b/tests/test_adb_manager.py index 5ab89516..3c2d56f0 100644 --- a/tests/test_adb_manager.py +++ b/tests/test_adb_manager.py @@ -69,7 +69,7 @@ def setUp(self): """ with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY]: - self.adb = ADBPython('IP:5555') + self.adb = ADBPython('HOST', 5555) def test_connect_success(self): """Test when the connect attempt is successful. @@ -194,7 +194,7 @@ def setUp(self): """Create an `ADBServer` instance. """ - self.adb = ADBServer('IP:5555', 'ADB_SERVER_IP') + self.adb = ADBServer('HOST', 5555, 'ADB_SERVER_IP') def test_available(self): """Test that the ``available`` property works correctly. @@ -252,7 +252,7 @@ def setUp(self): """ with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY]: - self.adb = ADBPython('IP:5555', 'adbkey') + self.adb = ADBPython('HOST', 5555, 'adbkey') def test_connect_success_with_priv_key(self): """Test when the connect attempt is successful when using a private key. @@ -282,7 +282,7 @@ 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') + self.adb = ADBPython('HOST', 5555) with patchers.patch_connect(True)[self.PATCH_KEY]: self.assertTrue(self.adb.connect()) diff --git a/tests/test_androidtv.py b/tests/test_androidtv.py index 2695734d..34d7728e 100644 --- a/tests/test_androidtv.py +++ b/tests/test_androidtv.py @@ -536,7 +536,7 @@ class TestAndroidTVPython(unittest.TestCase): def setUp(self): with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: - self.atv = AndroidTV('IP:5555') + self.atv = AndroidTV('HOST', 5555) def test_turn_on_off(self): """Test that the ``AndroidTV.turn_on`` and ``AndroidTV.turn_off`` methods work correctly. @@ -1061,7 +1061,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:5555', adb_server_ip='ADB_SERVER_IP') + self.atv = AndroidTV('HOST', 5555, adb_server_ip='ADB_SERVER_IP') class TestStateDetectionRulesValidator(unittest.TestCase): @@ -1071,11 +1071,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 - AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES1) - AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES2) - AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES3) - AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES4) - AndroidTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES5) + AndroidTV('HOST', 5555, state_detection_rules=STATE_DETECTION_RULES1) + AndroidTV('HOST', 5555, state_detection_rules=STATE_DETECTION_RULES2) + AndroidTV('HOST', 5555, state_detection_rules=STATE_DETECTION_RULES3) + AndroidTV('HOST', 5555, state_detection_rules=STATE_DETECTION_RULES4) + AndroidTV('HOST', 5555, state_detection_rules=STATE_DETECTION_RULES5) if __name__ == "__main__": diff --git a/tests/test_basetv.py b/tests/test_basetv.py index 6506b10d..ca5d3675 100644 --- a/tests/test_basetv.py +++ b/tests/test_basetv.py @@ -81,7 +81,7 @@ class TestBaseTVPython(unittest.TestCase): def setUp(self): with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: - self.btv = BaseTV('IP:5555') + self.btv = BaseTV('HOST', 5555) def test_available(self): """Test that the available property works correctly. @@ -397,24 +397,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 - BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES1) - BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES2) - BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES3) - BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES4) - BaseTV('IP:5555', state_detection_rules=STATE_DETECTION_RULES5) + BaseTV('HOST', 5555, state_detection_rules=STATE_DETECTION_RULES1) + BaseTV('HOST', 5555, state_detection_rules=STATE_DETECTION_RULES2) + BaseTV('HOST', 5555, state_detection_rules=STATE_DETECTION_RULES3) + BaseTV('HOST', 5555, state_detection_rules=STATE_DETECTION_RULES4) + BaseTV('HOST', 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: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) + self.assertRaises(TypeError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID1) + self.assertRaises(KeyError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID2) + self.assertRaises(KeyError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID3) + self.assertRaises(KeyError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID4) + self.assertRaises(KeyError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID5) + self.assertRaises(KeyError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID6) + self.assertRaises(KeyError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID7) + self.assertRaises(KeyError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID8) + self.assertRaises(KeyError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID9) + self.assertRaises(KeyError, BaseTV, 'HOST', 5555, '', '', 5037, state_detection_rules=STATE_DETECTION_RULES_INVALID10) + self.assertRaises(KeyError, BaseTV, 'HOST', 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 a13f52cc..1623e261 100644 --- a/tests/test_firetv.py +++ b/tests/test_firetv.py @@ -134,7 +134,7 @@ class TestFireTVPython(unittest.TestCase): def setUp(self): with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]: - self.ftv = FireTV('IP:5555') + self.ftv = FireTV('HOST', 5555) def test_turn_on_off(self): """Test that the ``FireTV.turn_on`` and ``FireTV.turn_off`` methods work correctly. @@ -445,7 +445,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:5555', adb_server_ip='ADB_SERVER_PORT') + self.ftv = FireTV('HOST', 5555, adb_server_ip='ADB_SERVER_PORT') if __name__ == "__main__": diff --git a/tests/test_homeassistant.py b/tests/test_homeassistant.py index fa46e749..888819a6 100644 --- a/tests/test_homeassistant.py +++ b/tests/test_homeassistant.py @@ -242,7 +242,7 @@ class TestAndroidTVPythonImplementation(unittest.TestCase): def setUp(self): """Set up an `AndroidTVDevice` media player.""" 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") + aftv = setup("HOST", 5555, device_class="androidtv") self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, None, None) def test_reconnect(self): @@ -276,7 +276,7 @@ def test_reconnect(self): self.assertIsNotNone(self.aftv.state) assert ( - "ADB connection to {} successfully established".format(self.aftv.aftv.host) + "ADB connection to {}:{} successfully established".format(self.aftv.aftv.host, self.aftv.aftv.port) in logs.output[0] ) @@ -311,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:5555", adb_server_ip="ADB_SERVER_IP", device_class="androidtv" + "HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="androidtv" ) self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, None, None) @@ -341,8 +341,9 @@ def test_reconnect(self): self.assertIsNotNone(self.aftv.state) assert ( - "ADB connection to {} via ADB server {}:{} successfully established".format( + "ADB connection to {}:{} via ADB server {}:{} successfully established".format( self.aftv.aftv.host, + self.aftv.aftv.port, self.aftv.aftv.adb_server_ip, self.aftv.aftv.adb_server_port, ) @@ -372,7 +373,7 @@ class TestFireTVPythonImplementation(TestAndroidTVPythonImplementation): def setUp(self): """Set up a `FireTVDevice` media player.""" 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") + aftv = setup("HOST", 5555, device_class="firetv") self.aftv = FireTVDevice(aftv, "Fake Fire TV", {}, True, None, None) @@ -384,6 +385,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:5555", adb_server_ip="ADB_SERVER_IP", device_class="firetv" + "HOST", 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 bd770f9d..ae213dfc 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:5555', device_class='INVALID') + setup('HOST', 5555, device_class='INVALID') 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') + ftv = setup('HOST', 5555) self.assertIsInstance(ftv, FireTV) self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1) 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') + atv = setup('HOST', 5555) self.assertIsInstance(atv, AndroidTV) self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2) 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') + ftv = setup('HOST', 5555, device_class='androidtv') self.assertIsInstance(ftv, AndroidTV) self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1) 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') + atv = setup('HOST', 5555, device_class='firetv') self.assertIsInstance(atv, FireTV) self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)