Skip to content

Commit

Permalink
Validate for all models if sound mode is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
ol-iver committed Sep 22, 2024
1 parent 3adfc85 commit 3d94df8
Show file tree
Hide file tree
Showing 29 changed files with 155 additions and 25 deletions.
50 changes: 26 additions & 24 deletions denonavr/soundmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@
import attr

from .appcommand import AppCommands
from .const import (
ALL_ZONE_STEREO,
AVR_X,
AVR_X_2016,
DENON_ATTR_SETATTR,
SOUND_MODE_MAPPING,
)
from .exceptions import AvrCommandError, AvrProcessingError
from .const import ALL_ZONE_STEREO, DENON_ATTR_SETATTR, SOUND_MODE_MAPPING
from .exceptions import AvrCommandError, AvrIncompleteResponseError, AvrProcessingError
from .foundation import DenonAVRFoundation

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -106,16 +100,14 @@ async def async_setup(self) -> None:
"""Ensure that the instance is initialized."""
async with self._setup_lock:
_LOGGER.debug("Starting sound mode setup")
# Add tags for a potential AppCommand.xml update
for tag in self.appcommand_attrs:
self._device.api.add_appcommand_update_tag(tag)

# Soundmode is always available for AVR-X and AVR-X-2016 receivers
# For AVR receiver it will be tested during the first update
if self._device.receiver in [AVR_X, AVR_X_2016]:
self._support_sound_mode = True
else:
await self.async_update_sound_mode()

# The first update determines if sound mode is supported
await self.async_update_sound_mode()

if self.support_sound_mode:
# Add tags for a potential AppCommand.xml update
for tag in self.appcommand_attrs:
self._device.api.add_appcommand_update_tag(tag)

self._device.telnet_api.register_callback(
"MS", self._async_soundmode_callback
Expand Down Expand Up @@ -157,14 +149,22 @@ async def async_update_sound_mode(
"Device is not setup correctly, update method not set"
)

if self._is_setup and not self._support_sound_mode:
return

if self._device.use_avr_2016_update:
await self.async_update_attrs_appcommand(
self.appcommand_attrs, global_update=global_update, cache_id=cache_id
)
try:
await self.async_update_attrs_appcommand(
self.appcommand_attrs,
global_update=global_update,
cache_id=cache_id,
)
except (AvrProcessingError, AvrIncompleteResponseError):
_LOGGER.info("Sound mode not supported")
self._support_sound_mode = False
return
else:
urls = [self._device.urls.status, self._device.urls.mainzone]
if self._is_setup and not self._support_sound_mode:
return
# There are two different options of sound mode tags
try:
await self.async_update_attrs_status_xml(
Expand All @@ -179,7 +179,9 @@ async def async_update_sound_mode(
_LOGGER.info("Sound mode not supported")
self._support_sound_mode = False
return
self._support_sound_mode = True

self._support_sound_mode = True
_LOGGER.info("Sound mode supported")

def match_sound_mode(self) -> Optional[str]:
"""Match the raw_sound_mode to its corresponding sound_mode."""
Expand Down
4 changes: 3 additions & 1 deletion tests/test_denonavr.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ def custom_matcher(self, request: httpx.Request, *args, **kwargs):
content_str = request.read().decode("utf-8")
if "GetFriendlyName" in content_str:
ep_suffix = "-setup"
else:
elif "GetAllZoneSource" in content_str:
ep_suffix = "-update"
else:
ep_suffix = "-update-soundmode"
content = get_sample_content(
f"{self.testing_receiver}-AppCommand{ep_suffix}{port_suffix}.xml"
)
Expand Down
6 changes: 6 additions & 0 deletions tests/xml/AV7703-AppCommand-update-soundmode-8080.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>Dolby Digital + + Neural:X </surround>
</cmd>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/AVC-8500H-AppCommand-update-soundmode-8080.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>DTS Neo:X Cinema </surround>
</cmd>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/AVC-X3700H-AppCommand-update-soundmode-8080.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>Stereo </surround>
</cmd>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/AVR-1713-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>PLII Game </surround>
</cmd>
</rx>
3 changes: 3 additions & 0 deletions tests/xml/AVR-1912-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html><head><title>Document Error: Data follows</title></head>
<body><h2>Access Error: Data follows</h2>
<p>Form Deviceinfo.xml is not defined</p></body></html>
3 changes: 3 additions & 0 deletions tests/xml/AVR-2312CI-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html><head><title>Document Error: Data follows</title></head>
<body><h2>Access Error: Data follows</h2>
<p>Form Deviceinfo.xml is not defined</p></body></html>
3 changes: 3 additions & 0 deletions tests/xml/AVR-3311CI-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html><head><title>Document Error: Data follows</title></head>
<body><h2>Access Error: Data follows</h2>
<p>Form Deviceinfo.xml is not defined</p></body></html>
4 changes: 4 additions & 0 deletions tests/xml/AVR-3312-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<html><head><title>Document Error: Data follows</title></head>
<body><h2>Access Error: Data follows</h2>
<p>Form AppCommand.xml is not defined</p></body></html>

6 changes: 6 additions & 0 deletions tests/xml/AVR-3313-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>PLII Cinema </surround>
</cmd>
</rx>
4 changes: 4 additions & 0 deletions tests/xml/AVR-4810-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<html><head><title>Document Error: Data follows</title></head>
<body><h2>Access Error: Data follows</h2>
<p>Form AppCommand.xml is not defined</p></body></html>

6 changes: 6 additions & 0 deletions tests/xml/AVR-X1100W-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>DTS Neo:X Cinema </surround>
</cmd>
</rx>
3 changes: 3 additions & 0 deletions tests/xml/AVR-X2000-2-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html><head><title>Document Error: Data follows</title></head>
<body><h2>Access Error: Data follows</h2>
<p>Form AppCommand.xml is not defined</p></body></html>
3 changes: 3 additions & 0 deletions tests/xml/AVR-X2000-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
</rx>
3 changes: 3 additions & 0 deletions tests/xml/AVR-X2100W-2-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
</rx>
3 changes: 3 additions & 0 deletions tests/xml/AVR-X2100W-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html><head><title>Document Error: Data follows</title></head>
<body><h2>Access Error: Data follows</h2>
<p>Form AppCommand.xml is not defined</p></body></html>
6 changes: 6 additions & 0 deletions tests/xml/AVR-X4000-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>PLII Cinema </surround>
</cmd>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/AVR-X4100W-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>DTS Neo:X Cinema </surround>
</cmd>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/AVR-X4300H-AppCommand-update-soundmode-8080.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>DTS Neo:X Cinema </surround>
</cmd>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/M-CR510-2-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround></surround>
</cmd>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/M-CR510-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround></surround>
</cmd>
</rx>
4 changes: 4 additions & 0 deletions tests/xml/M-CR603-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<html><head><title>Document Error: Data follows</title></head>
<body><h2>Access Error: Data follows</h2>
<p>Form AppCommand.xml is not defined</p></body></html>

3 changes: 3 additions & 0 deletions tests/xml/M-RC610-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<rx>
</rx>
3 changes: 3 additions & 0 deletions tests/xml/NR1604-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/NR1609-AppCommand-update-soundmode-8080.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>DTS Neo:X Cinema </surround>
</cmd>
</rx>
3 changes: 3 additions & 0 deletions tests/xml/SR5008-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<rx>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/SR6011-AppCommand-update-soundmode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>Stereo </surround>
</cmd>
</rx>
6 changes: 6 additions & 0 deletions tests/xml/SR6012-AppCommand-update-soundmode-8080.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<rx>
<cmd>
<surround>Stereo </surround>
</cmd>
</rx>

0 comments on commit 3d94df8

Please sign in to comment.