From de788561eb39a16168061f419a07d8c26e1174de Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 May 2020 08:37:46 +0200 Subject: [PATCH] Parallelize SCPD XML requests to identify denon receivers / Push to version 0.9.2 --- HELP.md | 2 +- README.md | 2 +- README.rst | 2 +- denonavr/__init__.py | 2 +- denonavr/ssdp.py | 28 +++++++++++++++++----------- setup.py | 2 +- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/HELP.md b/HELP.md index 1463e1b..5999623 100644 --- a/HELP.md +++ b/HELP.md @@ -29,7 +29,7 @@ DATA __title__ = 'denonavr' VERSION - 0.9.1 + 0.9.2 ==================================================================================== diff --git a/README.md b/README.md index baf6311..5497275 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # denonavr [![Build Status](https://travis-ci.com/scarface-4711/denonavr.svg?branch=master)](https://travis-ci.com/scarface-4711/denonavr) -Automation Library for Denon AVR receivers - current version 0.9.1 +Automation Library for Denon AVR receivers - current version 0.9.2 ## Installation diff --git a/README.rst b/README.rst index d9322d9..37c0277 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,7 @@ denonavr .. |Build Status| .. image:: https://travis-ci.com/scarface-4711/denonavr.svg?branch=master :target: https://travis-ci.com/scarface-4711/denonavr -Automation Library for Denon AVR receivers - current version 0.9.1 +Automation Library for Denon AVR receivers - current version 0.9.2 Installation ------------ diff --git a/denonavr/__init__.py b/denonavr/__init__.py index 00deb62..00c3246 100644 --- a/denonavr/__init__.py +++ b/denonavr/__init__.py @@ -17,7 +17,7 @@ logging.getLogger(__name__).addHandler(logging.NullHandler()) __title__ = "denonavr" -__version__ = "0.9.1" +__version__ = "0.9.2" def discover(): diff --git a/denonavr/ssdp.py b/denonavr/ssdp.py index 4ef7192..cae288e 100755 --- a/denonavr/ssdp.py +++ b/denonavr/ssdp.py @@ -82,13 +82,19 @@ def identify_denonavr_receivers(): # Check which responding device is a DenonAVR device and prepare output receivers = [] - for url in urls: - try: - receiver = evaluate_scpd_xml(url) - except requests.exceptions.RequestException: - continue - if receiver: - receivers.append(receiver) + futures = [] + + with ThreadPoolExecutor() as executor: + for url in urls: + futures.append(executor.submit(evaluate_scpd_xml, url)) + + for future in futures: + try: + receiver = future.result() + except requests.exceptions.RequestException: + continue + if receiver is not None: + receivers.append(receiver) return receivers @@ -188,7 +194,7 @@ def evaluate_scpd_xml(url): device["manufacturer"]) if not device["manufacturer"] in SUPPORTED_MANUFACTURERS: - return False + return None if (root.find(SCPD_DEVICE).find(SCPD_DEVICETYPE).text in SUPPORTED_DEVICETYPES): @@ -201,7 +207,7 @@ def evaluate_scpd_xml(url): break if device_xml is None: - return False + return None if device_xml.find(SCPD_PRESENTATIONURL) is not None: device["host"] = urlparse( @@ -221,8 +227,8 @@ def evaluate_scpd_xml(url): except (AttributeError, ValueError, ET.ParseError) as err: _LOGGER.error( "Error occurred during evaluation of SCPD XML: %s", err) - return False + return None else: _LOGGER.debug("Host returned HTTP status %s when connecting to %s", res.status_code, url) - return False + return None diff --git a/setup.py b/setup.py index 6ade951..c2a5479 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import find_packages, setup setup(name='denonavr', - version='0.9.1', + version='0.9.2', description='Automation Library for Denon AVR receivers', long_description='Automation Library for Denon AVR receivers', url='https://github.com/scarface-4711/denonavr',