From 8b6cb2ca3826219063097decf4b6444da8696b67 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 May 2021 23:46:34 +0200 Subject: [PATCH] Raise timeout only when 80 and 8080 time out / catch httpx.RemoteProtocolError exception --- README.md | 4 ++-- README.rst | 2 +- denonavr/__init__.py | 2 +- denonavr/decorators.py | 6 ++++++ denonavr/foundation.py | 6 ++++-- setup.py | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a8da0d5..ce45c6e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # denonavr -[![Version](https://img.shields.io/badge/version-v0.10.6-orange.svg)](https://github.com/scarface-4711/denonavr) +[![Version](https://img.shields.io/badge/version-v0.10.7.dev1-orange.svg)](https://github.com/scarface-4711/denonavr) [![Build Status](https://travis-ci.com/scarface-4711/denonavr.svg?branch=master)](https://travis-ci.com/scarface-4711/denonavr) [![PyPi](https://img.shields.io/pypi/v/denonavr.svg)](https://pypi.org/project/denonavr) [![License](https://img.shields.io/github/license/scarface-4711/denonavr.svg)](LICENSE) -Automation Library for Denon AVR receivers - current version 0.10.6 +Automation Library for Denon AVR receivers - current version 0.10.7.dev1 ## Important change diff --git a/README.rst b/README.rst index d205a0e..200ab94 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.10.6 +Automation Library for Denon AVR receivers - current version 0.10.7.dev1 Important change ---------------- diff --git a/denonavr/__init__.py b/denonavr/__init__.py index cf52988..fb80f23 100644 --- a/denonavr/__init__.py +++ b/denonavr/__init__.py @@ -18,7 +18,7 @@ logging.getLogger(__name__).addHandler(logging.NullHandler()) __title__ = "denonavr" -__version__ = "0.10.6" +__version__ = "0.10.7.dev1" async def async_discover(): diff --git a/denonavr/decorators.py b/denonavr/decorators.py index 5409f15..828c11c 100644 --- a/denonavr/decorators.py +++ b/denonavr/decorators.py @@ -63,6 +63,12 @@ async def wrapper(*args, **kwargs): exc_info=True) raise AvrNetworkError( "NetworkError: {}".format(err), err.request) from err + except httpx.RemoteProtocolError as err: + _LOGGER.debug( + "Remote protocol error exception on request %s", err.request, + exc_info=True) + raise AvrInvalidResponseError( + "RemoteProtocolError: {}".format(err), err.request) from err except ( ET.ParseError, DefusedXmlException, ParseError, UnicodeDecodeError) as err: diff --git a/denonavr/foundation.py b/denonavr/foundation.py index f3f54fb..da7abbe 100644 --- a/denonavr/foundation.py +++ b/denonavr/foundation.py @@ -123,6 +123,7 @@ async def async_identify_receiver(self) -> None: # 2016 models has also some of the XML but not all, try first 2016 r_types = [AVR_X, AVR_X_2016] + timeout_errors = 0 for r_type in r_types: self.api.port = r_type.port # This XML is needed to get the sources of the receiver @@ -134,8 +135,9 @@ async def async_identify_receiver(self) -> None: _LOGGER.debug( "Connection error when identifying receiver", exc_info=err) - # Raise error only when ran over all models - if r_types.index(r_type) == len(r_types) - 1: + # Raise error only when occured at both types + timeout_errors += 1 + if timeout_errors == len(r_types): raise except AvrRequestError as err: diff --git a/setup.py b/setup.py index 145e49d..3a809c8 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import find_packages, setup setup(name='denonavr', - version='0.10.6', + version='0.10.7.dev1', description='Automation Library for Denon AVR receivers', long_description='Automation Library for Denon AVR receivers', url='https://github.com/scarface-4711/denonavr',