Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set timeout as parameter #866

Merged
merged 2 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion miio/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions miio/miioprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -89,15 +90,14 @@ 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.
If the target IP address is given, the handshake will be send as
an unicast packet.

:param str addr: Target IP address"""
timeout = 5
is_broadcast = addr is None
seen_addrs = [] # type: List[str]
if is_broadcast:
Expand Down