Skip to content

Commit

Permalink
Parallelize SCPD XML requests to identify denon receivers / Push to v…
Browse files Browse the repository at this point in the history
…ersion 0.9.2
  • Loading branch information
ol-iver committed May 25, 2020
1 parent a80b645 commit de78856
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DATA
__title__ = 'denonavr'

VERSION
0.9.1
0.9.2

====================================================================================

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand Down
2 changes: 1 addition & 1 deletion denonavr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
logging.getLogger(__name__).addHandler(logging.NullHandler())

__title__ = "denonavr"
__version__ = "0.9.1"
__version__ = "0.9.2"


def discover():
Expand Down
28 changes: 17 additions & 11 deletions denonavr/ssdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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(
Expand All @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit de78856

Please sign in to comment.