about summary refs log tree commit diff
path: root/third_party
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-04-26T13·50+0100
committerVincent Ambo <tazjin@google.com>2020-04-26T13·50+0100
commit0d7373974077125c15a7492edb37a9132998183a (patch)
tree4849eb93bc0a2e53f26f3b57de18026edb174389 /third_party
parent6644d0031da7af16effda4287ea2da17506ee415 (diff)
feat(3p/python/broadlink): Add max_devices discovery parameter r/689
This makes it possible to terminate early if the number of devices on
the network is known.
Diffstat (limited to 'third_party')
-rw-r--r--third_party/python/broadlink/broadlink/__init__.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/third_party/python/broadlink/broadlink/__init__.py b/third_party/python/broadlink/broadlink/__init__.py
index 27619a136e..0c70c4beae 100644
--- a/third_party/python/broadlink/broadlink/__init__.py
+++ b/third_party/python/broadlink/broadlink/__init__.py
@@ -72,7 +72,7 @@ def gendevice(devtype, host, mac, name=None, cloud=None):
     return device_class(host, mac, devtype, name=name, cloud=cloud)
 
 
-def discover(timeout=None, local_ip_address=None, discover_ip_address='255.255.255.255'):
+def discover(timeout=None, local_ip_address=None, discover_ip_address='255.255.255.255', max_devices=100):
     if local_ip_address is None:
         local_ip_address = socket.gethostbyname(socket.gethostname())
     if local_ip_address.startswith('127.'):
@@ -140,7 +140,7 @@ def discover(timeout=None, local_ip_address=None, discover_ip_address='255.255.2
         device = gendevice(devtype, host, mac, name=name, cloud=cloud)
         return device
 
-    while (time.time() - starttime) < timeout:
+    while ((time.time() - starttime) < timeout) and (len(devices) < max_devices):
         cs.settimeout(timeout - (time.time() - starttime))
         try:
             response = cs.recvfrom(1024)