diff --git a/miio/device.py b/miio/device.py index 45bbbb114..5092da1d5 100644 --- a/miio/device.py +++ b/miio/device.py @@ -113,10 +113,13 @@ def __init__( start_id: int = 0, debug: int = 0, lazy_discover: bool = True, + timeout: int = 5, ) -> None: self.ip = ip self.token = token - self._protocol = MiIOProtocol(ip, token, start_id, debug, lazy_discover) + self._protocol = MiIOProtocol( + ip, token, start_id, debug, lazy_discover, timeout + ) def send( self, diff --git a/miio/miioprotocol.py b/miio/miioprotocol.py index 880b6b57f..786149e6d 100644 --- a/miio/miioprotocol.py +++ b/miio/miioprotocol.py @@ -26,6 +26,7 @@ def __init__( start_id: int = 0, debug: int = 0, lazy_discover: bool = True, + timeout: int = 5, ) -> None: """ Create a :class:`Device` instance. @@ -43,7 +44,7 @@ def __init__( self.debug = debug self.lazy_discover = lazy_discover - self._timeout = 5 + self._timeout = timeout self._discovered = False self._device_ts = None # type: datetime.datetime self.__id = start_id @@ -89,7 +90,7 @@ def send_handshake(self, *, retry_count=3) -> Message: return m @staticmethod - def discover(addr: str = None) -> Any: + def discover(addr: str = None, timeout: int = 5) -> Any: """Scan for devices in the network. This method is used to discover supported devices by sending a handshake message to the broadcast address on port 54321. @@ -97,7 +98,6 @@ def discover(addr: str = None) -> Any: an unicast packet. :param str addr: Target IP address""" - timeout = 5 is_broadcast = addr is None seen_addrs = [] # type: List[str] if is_broadcast: