Skip to content

Commit

Permalink
Replace async_lru by asyncstdlib / fix issues with missing mainzone U…
Browse files Browse the repository at this point in the history
…RL in zones / don't raise AvrProcessingError when tonecontrol update fails
  • Loading branch information
ol-iver committed May 2, 2021
1 parent 6294bb3 commit 77fa2fe
Show file tree
Hide file tree
Showing 22 changed files with 957 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# denonavr
[![Version](https://img.shields.io/badge/version-v0.10.5-orange.svg)](https://github.com/scarface-4711/denonavr)
[![Version](https://img.shields.io/badge/version-v0.10.6-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.5
Automation Library for Denon AVR receivers - current version 0.10.6

## Important change

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.10.5
Automation Library for Denon AVR receivers - current version 0.10.6

Important change
----------------
Expand Down
2 changes: 1 addition & 1 deletion denonavr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
logging.getLogger(__name__).addHandler(logging.NullHandler())

__title__ = "denonavr"
__version__ = "0.10.5"
__version__ = "0.10.6"


async def async_discover():
Expand Down
6 changes: 3 additions & 3 deletions denonavr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import attr
import httpx

from async_lru import alru_cache
from asyncstdlib import lru_cache
from defusedxml.ElementTree import fromstring

from .appcommand import AppCommandCmd
Expand Down Expand Up @@ -127,7 +127,7 @@ async def async_get_command(self, request: str) -> str:

@set_cache_id
@cache_clear_on_exception
@alru_cache(maxsize=32, cache_exceptions=False)
@lru_cache(maxsize=32)
@async_handle_receiver_exceptions
async def async_get_xml(
self,
Expand All @@ -146,7 +146,7 @@ async def async_get_xml(

@set_cache_id
@cache_clear_on_exception
@alru_cache(maxsize=32, cache_exceptions=False)
@lru_cache(maxsize=32)
@async_handle_receiver_exceptions
async def async_post_appcommand(
self,
Expand Down
6 changes: 2 additions & 4 deletions denonavr/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@

# Zone 2 URLs
STATUS_Z2_URL = "/goform/formZone2_Zone2XmlStatus.xml"
MAINZONE_Z2_URL = None
COMMAND_SEL_SRC_Z2_URL = "/goform/formiPhoneAppDirect.xml?Z2"
COMMAND_FAV_SRC_Z2_URL = "/goform/formiPhoneAppDirect.xml?Z2"
COMMAND_POWER_ON_Z2_URL = "/goform/formiPhoneAppPower.xml?2+PowerOn"
Expand All @@ -165,7 +164,6 @@

# Zone 3 URLs
STATUS_Z3_URL = "/goform/formZone3_Zone3XmlStatus.xml"
MAINZONE_Z3_URL = None
COMMAND_SEL_SRC_Z3_URL = "/goform/formiPhoneAppDirect.xml?Z3"
COMMAND_FAV_SRC_Z3_URL = "/goform/formiPhoneAppDirect.xml?Z3"
COMMAND_POWER_ON_Z3_URL = "/goform/formiPhoneAppPower.xml?3+PowerOn"
Expand Down Expand Up @@ -204,7 +202,7 @@
appcommand=APPCOMMAND_URL,
appcommand0300=APPCOMMAND0300_URL,
status=STATUS_Z2_URL,
mainzone=MAINZONE_Z2_URL,
mainzone=MAINZONE_URL,
deviceinfo=DEVICEINFO_URL,
netaudiostatus=NETAUDIOSTATUS_URL,
tunerstatus=TUNERSTATUS_URL,
Expand All @@ -228,7 +226,7 @@
appcommand=APPCOMMAND_URL,
appcommand0300=APPCOMMAND0300_URL,
status=STATUS_Z3_URL,
mainzone=MAINZONE_Z3_URL,
mainzone=MAINZONE_URL,
deviceinfo=DEVICEINFO_URL,
netaudiostatus=NETAUDIOSTATUS_URL,
tunerstatus=TUNERSTATUS_URL,
Expand Down
4 changes: 2 additions & 2 deletions denonavr/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ async def wrapper(*args, **kwargs):

def cache_clear_on_exception(func: Coroutine) -> Coroutine:
"""
Decorate a function to clear alru_cache if an exception occurs.
Decorate a function to clear lru_cache if an exception occurs.
The decorator must be placed right before the @alru_cache decorator.
The decorator must be placed right before the @lru_cache decorator.
It prevents memory leaks in home-assistant when receiver instances are
created and deleted right away in case the device is offline on setup.
"""
Expand Down
8 changes: 7 additions & 1 deletion denonavr/foundation.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ async def async_update_power_status_xml(
cache_id: Optional[Hashable] = None):
"""Update power status from status xml."""
# URLs to be scanned
urls = [self.urls.status, self.urls.mainzone]
urls = [self.urls.status]
if self.zone == MAIN_ZONE:
urls.append(self.urls.mainzone)
# Variables with their tags to be updated
update_attrs = {"_power": "./Power/value"}

Expand Down Expand Up @@ -550,6 +552,10 @@ async def async_update_attrs_appcommand(
raise AvrProcessingError(
"Not all attributes updated, those are left: {}".format(
update_attrs))
if update_attrs and ignore_missing_response is True:
_LOGGER.debug(
"Not all attributes updated, those are left and ignored "
"deliberately: %s", update_attrs)

async def async_update_attrs_status_xml(
self,
Expand Down
8 changes: 5 additions & 3 deletions denonavr/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .appcommand import AppCommands
from .const import (
ALBUM_COVERS_URL, APPCOMMAND_CMD_TEXT, AVR, AVR_X_2016, AVR_X,
CHANGE_INPUT_MAPPING, DENON_ATTR_SETATTR, NETAUDIO_SOURCES,
CHANGE_INPUT_MAPPING, DENON_ATTR_SETATTR, MAIN_ZONE, NETAUDIO_SOURCES,
PLAYING_SOURCES, POWER_ON, SOURCE_MAPPING, STATE_PLAYING, STATE_PAUSED,
STATIC_ALBUM_URL, ZONE2, ZONE3)
from .exceptions import AvrCommandError, AvrProcessingError, AvrRequestError
Expand Down Expand Up @@ -293,7 +293,7 @@ async def async_get_changed_sources_status_xml(
if self._device.receiver == AVR_X:
xml = await self._device.api.async_get_xml(
self._device.urls.status, cache_id=cache_id)
# URL only available for Main Zone.
# These are the input functions of Main Zone.
elif self._device.receiver == AVR:
xml = await self._device.api.async_get_xml(
self._device.urls.mainzone, cache_id=cache_id)
Expand Down Expand Up @@ -497,7 +497,9 @@ async def async_update_state(
self.appcommand_attrs, global_update=global_update,
cache_id=cache_id)
elif self._device.use_avr_2016_update is False:
urls = [self._device.urls.status, self._device.urls.mainzone]
urls = [self._device.urls.status]
if self._device.zone == MAIN_ZONE:
urls.append(self._device.urls.mainzone)
await self.async_update_attrs_status_xml(
self.status_xml_attrs, urls, cache_id=cache_id)
else:
Expand Down
2 changes: 1 addition & 1 deletion denonavr/soundmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async def async_update_sound_mode(
self,
global_update: bool = False,
cache_id: Optional[Hashable] = None):
"""Update volume status of device."""
"""Update sound mode status of device."""
if self._device.use_avr_2016_update is True:
await self.async_update_attrs_appcommand(
self.appcommand_attrs, global_update=global_update,
Expand Down
2 changes: 1 addition & 1 deletion denonavr/tonecontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def async_update_tone_control(
if self._device.use_avr_2016_update is True:
await self.async_update_attrs_appcommand(
self.appcommand_attrs, global_update=global_update,
cache_id=cache_id)
cache_id=cache_id, ignore_missing_response=True)
elif self._device.use_avr_2016_update is False:
# Not available
pass
Expand Down
6 changes: 4 additions & 2 deletions denonavr/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import attr

from .appcommand import AppCommands
from .const import DENON_ATTR_SETATTR, STATE_ON
from .const import DENON_ATTR_SETATTR, MAIN_ZONE, STATE_ON
from .exceptions import AvrCommandError, AvrProcessingError
from .foundation import DenonAVRFoundation

Expand Down Expand Up @@ -86,7 +86,9 @@ async def async_update_volume(
self.appcommand_attrs, global_update=global_update,
cache_id=cache_id)
elif self._device.use_avr_2016_update is False:
urls = [self._device.urls.status, self._device.urls.mainzone]
urls = [self._device.urls.status]
if self._device.zone == MAIN_ZONE:
urls.append(self._device.urls.mainzone)
await self.async_update_attrs_status_xml(
self.status_xml_attrs, urls, cache_id=cache_id)
else:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
async_lru>=1.0.2
asyncstdlib>=3.9.1
attrs>=20.3.0
defusedxml>=0.6.0
defusedxml>=0.7.1
httpx>=0.16.1
netifaces>=0.10.9
6 changes: 3 additions & 3 deletions 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.10.5',
version='0.10.6',
description='Automation Library for Denon AVR receivers',
long_description='Automation Library for Denon AVR receivers',
url='https://github.com/scarface-4711/denonavr',
Expand All @@ -13,9 +13,9 @@
license='MIT',
packages=find_packages(),
install_requires=[
'async_lru>=1.0.2',
'asyncstdlib>=3.9.1',
'attrs>=20.3.0',
'defusedxml>=0.6.0',
'defusedxml>=0.7.1',
'httpx>=0.16.1',
'netifaces>=0.10.9'],
tests_require=['tox'],
Expand Down
1 change: 1 addition & 0 deletions tests/test_denonavr.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"AVR-X4300H": (ZONE2_ZONE3, denonavr.const.AVR_X_2016),
"AVR-X1100W": (ZONE2, denonavr.const.AVR_X),
"SR6012": (ZONE2, denonavr.const.AVR_X_2016),
"M-CR510": (NO_ZONES, denonavr.const.AVR_X),
}

APPCOMMAND_URL = "/goform/AppCommand.xml"
Expand Down
6 changes: 6 additions & 0 deletions tests/xml/M-CR510-AppCommand-setup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<friendlyname>Marantz M-CR510</friendlyname>
</cmd>
</rx>
118 changes: 118 additions & 0 deletions tests/xml/M-CR510-AppCommand-update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<zone1>ON</zone1>
</cmd>
<cmd>
<zone1>
<source>AUXB</source>
</zone1>
</cmd>
<cmd>
<functionrename>
<list>
<name>SIRIUS</name>
<rename>SiriusXM</rename>
</list>
<list>
<name>PANDORA</name>
<rename>Pandora</rename>
</list>
<list>
<name>IRADIO</name>
<rename>Internet Radio</rename>
</list>
<list>
<name>SERVER</name>
<rename>Music Server</rename>
</list>
<list>
<name>AUXB</name>
<rename>AUX:Analog In</rename>
</list>
<list>
<name>AUXC</name>
<rename>Analog In 2</rename>
</list>
<list>
<name>AUXD</name>
<rename>AUX:Digital In</rename>
</list>
<list>
<name>USB</name>
<rename>Front USB</rename>
</list>
<list>
<name>USB2</name>
<rename>Rear USB</rename>
</list>
<list>
<name>SpotifyConnect</name>
<rename>Spotify</rename>
</list>
</functionrename>
</cmd>
<cmd>
<functiondelete>
<list>
<name>SiriusXM</name>
<FuncName>SiriusXM</FuncName>
<use>1</use>
</list>
<list>
<name>Pandora</name>
<FuncName>Pandora</FuncName>
<use>1</use>
</list>
<list>
<name>Internet Radio</name>
<FuncName>Internet Radio</FuncName>
<use>1</use>
</list>
<list>
<name>Music Server</name>
<FuncName>Music Server</FuncName>
<use>1</use>
</list>
<list>
<name>AUX:Analog In</name>
<FuncName>AUX2</FuncName>
<use>1</use>
</list>
<list>
<name>Analog In 2</name>
<FuncName>AUX3</FuncName>
<use>1</use>
</list>
<list>
<name>AUX:Digital In</name>
<FuncName>AUX4</FuncName>
<use>1</use>
</list>
<list>
<name>Front USB</name>
<FuncName>USB</FuncName>
<use>1</use>
</list>
<list>
<name>Rear USB</name>
<FuncName>USB2</FuncName>
<use>1</use>
</list>
</functiondelete>
</cmd>
<cmd>
<surround></surround>
</cmd>
<error>2</error>
<cmd>
<zone1>
<volume>-75.0</volume>
<disptype>RELATIVE</disptype>
<dispvalue>-75.0dB</dispvalue>
</zone1>
</cmd>
<cmd>
<zone1>off</zone1>
</cmd>
</rx>
Loading

0 comments on commit 77fa2fe

Please sign in to comment.