From 0d7373974077125c15a7492edb37a9132998183a Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 26 Apr 2020 14:50:04 +0100 Subject: feat(3p/python/broadlink): Add max_devices discovery parameter This makes it possible to terminate early if the number of devices on the network is known. --- third_party/python/broadlink/broadlink/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'third_party') diff --git a/third_party/python/broadlink/broadlink/__init__.py b/third_party/python/broadlink/broadlink/__init__.py index 27619a136ea3..0c70c4beaed3 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) -- cgit 1.4.1