Skip to content

Commit

Permalink
Merge 52c9501 into 133063c
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Oct 7, 2019
2 parents 133063c + 52c9501 commit 958da64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions androidtv/adb_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from adb_shell.auth.sign_pythonrsa import PythonRSASigner
from adb_messenger.client import Client

from .constants import DEFAULT_AUTH_TIMEOUT_S

_LOGGER = logging.getLogger(__name__)

#: Use a timeout for the ADB threading lock if it is supported
Expand Down Expand Up @@ -64,13 +66,15 @@ def close(self):
"""
self._adb.close()

def connect(self, always_log_errors=True):
def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S):
"""Connect to an Android TV / Fire TV device.
Parameters
----------
always_log_errors : bool
If True, errors will always be logged; otherwise, errors will only be logged on the first failed reconnect attempt
auth_timeout_s : float
Authentication timeout (in seconds)
Returns
-------
Expand Down Expand Up @@ -99,9 +103,9 @@ def connect(self, always_log_errors=True):
signer = PythonRSASigner(pub, priv)

# Connect to the device
self._adb.connect(rsa_keys=[signer], auth_timeout_s=0.1)
self._adb.connect(rsa_keys=[signer], auth_timeout_s=auth_timeout_s)
else:
self._adb.connect(auth_timeout_s=0.1)
self._adb.connect(auth_timeout_s=auth_timeout_s)

# ADB connection successfully established
self._available = True
Expand Down
3 changes: 3 additions & 0 deletions androidtv/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,6 @@
MUTED_REGEX_PATTERN = r"Muted: (.*?)\W"
STREAM_MUSIC_REGEX_PATTERN = "STREAM_MUSIC(.*?)- STREAM"
VOLUME_REGEX_PATTERN = r"\): (\d{1,})"

#: Default authentication timeout (in s) for :meth:`adb_shell.tcp_handle.TcpHandle.connect`
DEFAULT_AUTH_TIMEOUT_S = 0.1

0 comments on commit 958da64

Please sign in to comment.